Please help me out. I am really not good at polymorphism. I have to classes inherited one from the other.
EDIT: Sorry, fully my mistake. Even I have passed about 2 hours to find the problem. Those who are interested (thanks for all the help)
if (type.compare("TEST1") == 0) result = new Test(ID, database);
if (type.compare("TEST2") == 0) result = new Test(ID, database);
if (type.compare("TOR") == 0) result = new Tor(ID, database);
"==0" was completely missing.
class A {
public:
void go() {do();}
virtual void do() {printf('A');}
}
class B:public A {
virtual void do() {printf('B');}
}
int main {
A* obj = new B();
obj->go();
}
The result is 'A' not 'B'. How can I manage to make it 'B'?
Thanks.