[gameprogrammer] Re: Pure virtual function getting called

When the base class's constructor is called the vtable hasn't been created
yet so the base constructor has no choice but try to call its own version of
the function.

Perhaps you could store a string in your base class and initialise it via
the base constructor from the derived class.

Good luck.


-----Original Message-----
From: gameprogrammer-bounce@xxxxxxxxxxxxx
[mailto:gameprogrammer-bounce@xxxxxxxxxxxxx] On Behalf Of Kevin Jenkins
Sent: Thursday, 20 May 2004 11:55 AM
To: gameprogrammer@xxxxxxxxxxxxx
Subject: [gameprogrammer] Pure virtual function getting called

I have this in the base class
virtual char* GetClassName(void) const=0;

This in the derived class
virtual char* GetClassName(void) const {return "Player";}

Yet when I call GetClassName within the base class constructor, it is still
calling the base class version of GetClassName and complaints about calling
a pure virtual function.

On a similar topic, all GetClassName does is return the name of the class it
is enclosed in.  I made it pure virtual so the users wouldn't forget to
define it.  But if there is an automatic way to do this please let me know.



---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html







---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: