I am testing some API code.
the SimpleClient.h header file contains the following:
class SimpleClient : public EWrapper, public EClientSocket { // The class
public: // Access specifier
SimpleClient(const char* host, int port, int clientId = 0); // this is line 17
~SimpleClient();
EReader *reader;
EReaderOSSignal signal;
/// begin virtual functions
// Event handling functions
void tickPrice(TickerId tickerId, TickType field, double price, const TickAttrib& attrib) {};
void tickSize(TickerId tickerId, TickType field, int size) {};
void tickOptionComputation(TickerId tickerId, TickType tickType, double impliedVol, double delta,
double optPrice, double pvDividend, double gamma, double vega, double theta, double undPrice) {};
inside Main.cpp
int main() {
// Connect to TWS or IB Gateway
SimpleClient sc("127.0.0.1", 1162709, 0);
// Request the current time
sc.reqCurrentTime();
// Sleep while the message is received
std::this_thread::sleep_for(std::chrono::seconds(1));
// Read the message
sc.signal.waitForSignal();
sc.reader->processMsgs();
// Disconnect
sc.eDisconnect();
return 0;
}
Inside SimpleClient.cpp there are definition outside the SimpleClient class:
SimpleClient::SimpleClient(const char *host, int port, int clientId) :
signal(1000), EClientSocket(this, &signal) {
// Connect to TWS
bool conn = eConnect(host, port, clientId, false);
if (conn) {
// Launch the reader thread
reader = new EReader(this, &signal);
reader->start();
}
else
std::cout << "Failed to connect" << std::endl;
}
SimpleClient::~SimpleClient() { delete reader; }
When running int main() the following error appears:
error C2259: 'SimpleClient': cannot instantiate abstract class
SimpleClient.h(17): message : see declaration of SimpleClient
As I understand it there is the class SimpleClient and inside there is public access specifier which defines on line 17 SimpleClient(const char* host, int port, int clientId = 0); and ~SimpleClient(); they are public constructor/destructor and can be accessed from outside of the class.
inside Main.cpp. calling
SimpleClient sc("127.0.0.1", 1162709, 0);
is creating an object sc by calling the constructor as defined in the SimpleClient.h file and SimpleClient.cpp....?
In this case what exactly is going wrong and firing off error
error C2259: 'SimpleClient': cannot instantiate abstract class
SimpleClient.h(17): message : see declaration of 'SimpleClient'
Main.cpp(8,16): message : due to following members:
Main.cpp(8,16): message : 'void EWrapper::tickSize(TickerId,TickType,Decimal)': is abstract
Compiler Error C2259 link: https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/compiler-error-c2259?view=msvc-170