-
May you inform me what i should do so that the following:
Code:
#include <iostream>
class class_a
{public:
int x;
int func(){return 1;}
};
class class_b:public class_a
{public:
int func(){return 2;}
int x;
};
int main()
{
class_a **table=new class_a*[5];
class_b *node=new class_b();
table[0]=node;
int x=table[0]->func();
std::cout<<x;
system("pause");
return 0;
}
prints "2" instead of "1"?
-
func() should be a virtual function. You should also have virtual destructors for both classes. You should also delete/delete[] properly.
-
Does this work even when there is only a declaration (extern class_a ** table)
in the file that i call the function?
-Silly post forget about it .. :(-