C++ question

David Faure david at mandrakesoft.com
Wed Sep 25 12:35:27 BST 2002


On Wed, 25 Sep 2002, Michael Goffioul wrote:

> Can I call a pure virtual function in the constructor of the abstract
> class? That is
>
> class A
> {
> public:
>    A() { func(); }
>    virtual void func() = 0;
> };

Impossible. When A is built, there is not yet a reimplementation of func()
registered in the vtable. This is a good way to see the nice "pure virtual
method called".
You have to simplify the constructors, and add some virtual init() that
does the job, for instance.

David.






More information about the kde-core-devel mailing list