J
John Doe
I don't understand one thing about the diamond multiple inheritance. See
the code:
------------------------------------------------------
class A
{
public:
void f() {std::cout("A");}
};
class B : virtual public A
{
public:
void f() {std::cout("B");}
};
class C : virtual public A
{
};
class D : public B, public C
{
};
int main (.........) {
D d;
d.f();
........
}
------------------------------------------------------
This code compiles OK and the B::f() is called.
BUT if I remove the virtual from the following lines:
class B : virtual public A
class C : virtual public A
THEN it gives compile error:
d:\Data\VC++7.1_projects\Prova1\Prova1.cpp(73) : error C2385: ambiguous
access of 'f' in 'D'
could be the 'f' in base 'B::f'
or the 'f' in base 'A::f'
d:\Data\VC++7.1_projects\Prova1\Prova1.cpp(73) : error C3861: 'f':
identifier not found, even with argument-dependent lookup
WHY this different behaviour???
the code:
------------------------------------------------------
class A
{
public:
void f() {std::cout("A");}
};
class B : virtual public A
{
public:
void f() {std::cout("B");}
};
class C : virtual public A
{
};
class D : public B, public C
{
};
int main (.........) {
D d;
d.f();
........
}
------------------------------------------------------
This code compiles OK and the B::f() is called.
BUT if I remove the virtual from the following lines:
class B : virtual public A
class C : virtual public A
THEN it gives compile error:
d:\Data\VC++7.1_projects\Prova1\Prova1.cpp(73) : error C2385: ambiguous
access of 'f' in 'D'
could be the 'f' in base 'B::f'
or the 'f' in base 'A::f'
d:\Data\VC++7.1_projects\Prova1\Prova1.cpp(73) : error C3861: 'f':
identifier not found, even with argument-dependent lookup
WHY this different behaviour???