This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ - Calling virtual function from constructor


Hi,

I have a question that regards C++. In my program I have a class with some
virtual functions. One virtual Function does some initialization specific to
the derived class. It looks someThing like this:

class scmObject
{
  protected:
    virtual void    construct()=0;
  public:
    scmObject();
}

scmObject::scmObject()
{
  ...
  construct();
}

When I try to compile this I get:
scmObject.cpp: In method `scmObject::scmObject(BRANCH *)':
scmObject.cpp:50: abstract virtual `void scmObject::construct(BRANCH *)'
called from constructor

When I chage it like this I can compile it:

class scmObject
{
  protected:
    virtual void    construct()=0;
    void     init();
public:
    scmObject();
}

scmObject::scmObject()
{
  ...
  init();
}

void scmObject::init()
{
  construct();
}

Why can I not or how could I call a virtual function from the contstructor?


Thanks


Eddy


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]