[gameprogrammer] Re: Pure virtual function getting called
- From: kevin-shea@xxxxxxxx
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Thu, 20 May 2004 07:34:05 +0100
Hi Kevin,
I seen to remember running into this problem at one point and
believe its "undefined behaviour" according to the standard,
i.e. compiler-dependent. Could be wrong though :)
A simple alternative might be to store the class name in the
base class and pass in its value via the constructor. Get's
you past calling a virtual function at the cost of allocating
a string for every class instance.
Kev
> 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
- Follow-Ups:
- [gameprogrammer] Re: Pure virtual function getting called
- From: Dave Slutzkin
Other related posts:
- » [gameprogrammer] Pure virtual function getting called
- » [gameprogrammer] Re: Pure virtual function getting called
- » [gameprogrammer] Re: Pure virtual function getting called
- » [gameprogrammer] Re: Pure virtual function getting called
- » [gameprogrammer] Re: Pure virtual function getting called
- » [gameprogrammer] Re: Pure virtual function getting called
- » [gameprogrammer] Re: Pure virtual function getting called
- » [gameprogrammer] Re: Pure virtual function getting called
- » [gameprogrammer] Re: Pure virtual function getting called
- [gameprogrammer] Re: Pure virtual function getting called
- From: Dave Slutzkin