I guess what you need to do is make parent->GetDimension() a pure firtual function, which means all children must implement it.
class base
{
// pure virtual function
int getDimention() = 0;
...
};
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
the problem is that you are calling a virtual function during the construction of the base class. this will not behave the way you expect it to behave; the wrong vtable is being pointed to at the time. if you call virtual functions during construction or destruction, such calls will never be dispatched to a more derived class than the one that is currently being constructed or destroyed.
for a more detailed explanation of why this is so (and why it is a good thing) and a possible work around, see http://www.artima.com/cppsource/nevercall.html
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287