Hi,
        I've found that this article explains very well why one *cannot*
call a virtual function during construction (or destruction).

        http://www.artima.com/cppsource/nevercall.html

HTH,

Fang

> I have created a base class who's constructor calls a pure virtual
> function I derive this class, implement the function, compile and
> receive this error message, "error: abstract virtual `IDXTYPE
> DataSet<DATA, IDXTYPE>::indexFxn(uint) [with DATA = float, IDXTYPE =
> float]' called from constructor"
>
> Without context to my code basically reads, "error: abstract virtual
> function called from constructor"
>
> I know that it would not make sense for the base class to call a pure
> virtual function. However, this constructor is being called in
> response to a derived class of the base being initialized who defines
> the pure virtual function of the base.
>
> I can see how this error may happen if the constructor for the base
> class is called before the derived class at which time the pointer to
> the derived class' implementation of the base class' virtual function
> is not initialized (I don't know for sure if this is the order of what
> happens but it is my best educated guess). I don't see that this error
> is necessary, unless the derived class does not implement the pure
> virtual function of the base.  Even if this were the case, the derived
> class could initialize the pointer table with it's implementation for
> the base class pure virtual function before the base class constructor
> call to the pure virtual function?
>
> Is this behaviour a cause of the C++ standard or is it specific to GCC?

David Fang
Computer Systems Laboratory
Electrical & Computer Engineering
Cornell University
http://www.csl.cornell.edu/~fang/
        -- (2400 baud? Netscape 3.0?? lynx??? No problem!)

Reply via email to