Calling a pure virtual function

Florian Weimer fw@deneb.enyo.de
Sat Jul 9 11:28:00 GMT 2005


* Adam Nielsen:

> class Base {
>   public:
>     Base()
>     {
>       cout << "This is class " << this->number();
>     }
>
>     virtual int number() = 0;
> };

Roughly speaking, when number() is invoked, the object still has type
Base (with a corresponding vtable).  One's constructor will change the
type once the Base part has been constructed.

The following FAQ entry covers this:

http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.3



More information about the Gcc mailing list