M
marv
If I have abstract base classes like these:
//---------
class IBase
{
public:
virtual void Action(void) = 0;
};
class IDerived : public IBase
{
public:
virtual void Whatever(void) = 0;
};
//-------
....I expected to be able to create implentations as follows...
//-------
class CBase : public IBase
{
public:
void Action(void) { // do something }
};
class CDerived : public IDerived, public CBase
{
public
void Whatever(void) { // do something else }
};
//-------
....thinking that the IBase::Action() in CDerived (inherited from
IDerived) would be satisfied by the CBase implementation, but I get a
"cannot allocate an object of type CDerived" error as IBase::Action()
is still abstract.
I bet this is to do with them having different entries in the v-table
or something? Like there's an entry for CBase::Action() in CDerived,
but not IBase::Action(), so the linker isn't satisfied. Is there any
way I can fix this without having to declare "void Action(void)" in
CDerived as well? My real code will have many such inherited methods
and I don't want to have to reimplement them all each time, doesn't
that defeat the object of inheritance? I need pure virtual interfaces
to all my classes, and also the inherited structure of the
implementations.
I'm sure this is quite simple, but any advice would be much appreciated!
//---------
class IBase
{
public:
virtual void Action(void) = 0;
};
class IDerived : public IBase
{
public:
virtual void Whatever(void) = 0;
};
//-------
....I expected to be able to create implentations as follows...
//-------
class CBase : public IBase
{
public:
void Action(void) { // do something }
};
class CDerived : public IDerived, public CBase
{
public
void Whatever(void) { // do something else }
};
//-------
....thinking that the IBase::Action() in CDerived (inherited from
IDerived) would be satisfied by the CBase implementation, but I get a
"cannot allocate an object of type CDerived" error as IBase::Action()
is still abstract.
I bet this is to do with them having different entries in the v-table
or something? Like there's an entry for CBase::Action() in CDerived,
but not IBase::Action(), so the linker isn't satisfied. Is there any
way I can fix this without having to declare "void Action(void)" in
CDerived as well? My real code will have many such inherited methods
and I don't want to have to reimplement them all each time, doesn't
that defeat the object of inheritance? I need pure virtual interfaces
to all my classes, and also the inherited structure of the
implementations.
I'm sure this is quite simple, but any advice would be much appreciated!