Consider the following basic code:
As you see, D inherits 2 versions of proc a deferred one(from A) and an effective(from C). It should be logical that D inherits proc from C, as it is made effective. Instead of that the compiler badly complains of :
The compiler(at least cl) can't see that C:
roc is the version to use in class D.
The problem can be solved by redeclaring proc in class D :
In complex class hierarchies(where multiple inheritance is used), with many routines, this can lead to lots of silly redeclarations.
Does anyone know a better solution? I heard of the virtual operator for managing class multiple inheritance, but found nothing clear about it.
--
Globos
Code:
class A
{
public:
virtual void proc () = 0;//deferred procedure
};
class B : public A
{ };
class C : public A
{
public:
virtual void proc ()//basic implementation
{ }
};
class D : public B, public C
{ };
int main ()
{
D d;
return 0;
}
As you see, D inherits 2 versions of proc a deferred one(from A) and an effective(from C). It should be logical that D inherits proc from C, as it is made effective. Instead of that the compiler badly complains of :
Code:
lign(22): error C2259: 'D' : cannot instantiate abstract class due to following members:
lign(17) : see declaration of 'D'
lign(22): 'void __thiscall A::proc(void)' : pure virtual function was not defined
lign(4) : see declaration of 'proc'
lign(22): 'D' : cannot instantiate abstract class due to following members:
lign(17) : see declaration of 'D'
lign(22): 'void __thiscall A::proc(void)' : pure virtual function was not defined
lign(4) : see declaration of 'proc'
The compiler(at least cl) can't see that C:
The problem can be solved by redeclaring proc in class D :
Code:
class D : public C, public D
{
public:
virtual void proc ()
{
C::proc ();
}
};
In complex class hierarchies(where multiple inheritance is used), with many routines, this can lead to lots of silly redeclarations.
Does anyone know a better solution? I heard of the virtual operator for managing class multiple inheritance, but found nothing clear about it.
--
Globos