I'm stuck and already tried a alot to solve this "virtual" problem and so I beg you to help me, cause it's probably something stupid that a "trained eye" can solve in seconds..
The problem: When I do the following in main:
PrologConnector swiProlog;
swiProlog = PrologConnector::connectorFactory(PrologConnector::swi,argv);
swiProlog.send("blabla");
always the send method of the PrologConnector class is called, but not the one from the subclass.. Do you see the problem?
Thanks for the help!!
Here's the code: PrologConnector.h
class PrologConnector {
virtual int send(char * cmd);
virtual int init(char **argv);
static PrologConnector connectorFactory(Prolog prolog, char ** argv);
};
PrologConnector.cpp
int PrologConnector::send(char * argv) {
std::cout << "not wanted"<<std::endl;
return 0;
}
int PrologConnector::init(char **argv) {
//TODO add implementation
return 0;
}
PrologConnector PrologConnector::connectorFactory(Prolog prolog, char **argv) {
if (prolog == swi) {
SWIConnector sc;
sc.init(argv);
return sc;
}
std::cout <<"Error in initialization!"<<std::endl;
PrologConnector pc;
return pc;
}
SWIConnector.h:
class SWIConnector : public PrologConnector {
int send(char *cmd);
int init(char **argv);
};
SWIConnector.cpp:
int SWIConnector::init(char **argv) {
//some action going on
}
int SWIConnector::send(char * cmd) {
//some action going on
}