public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ - Calling virtual function from constructor
@ 2001-11-14 22:45 Eddy Ilg
  2001-11-15 18:19 ` Rob Newberry
  2001-11-16  1:18 ` Frank Schafer
  0 siblings, 2 replies; 3+ messages in thread
From: Eddy Ilg @ 2001-11-14 22:45 UTC (permalink / raw)
  To: gcc-help

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-11-23  7:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-14 22:45 C++ - Calling virtual function from constructor Eddy Ilg
2001-11-15 18:19 ` Rob Newberry
2001-11-16  1:18 ` Frank Schafer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).