Multiple Inheritance Diamond with Overriding, egcs problem?
Greg Badros
gjb@cs.washington.edu
Mon May 4 17:05:00 GMT 1998
I've a question regarding overriding of a method inherited from a class
at the top of the diamond in the famous MI virtual base class example.
Here's the specific code:
#include <iostream.h>
class C {
public:
C() { }
virtual void m() { cout << "C::m()" << endl; }
};
class A : public virtual C {
public:
A() { }
virtual void m() { cout << "A::m()" << endl; }
virtual void j() { m(); }
};
class B : public virtual C {
public:
B() { }
virtual void m() { cout << "B::m()" << endl; }
};
class D : public B, public A {
public:
D() { }
};
int main()
{
D d; /* egcs-1.02 gives me an error about virtual functions here */
}
This creates:
C
/ \
A B
\ /
D
and I expect to get some kind of ambiguity error, since D::m() is
ambiguous. Instead, egcs-1.02 reports:
mult-inheritance-and-overriding3.cc: In function `int main()':
mult-inheritance-and-overriding3.cc:39: cannot declare variable `d' to be of type `D'
mult-inheritance-and-overriding3.cc:39: since the following virtual functions are abstract:
mult-inheritance-and-overriding3.cc:39: void B::m()
Could this error message be in need of a rewrite? The ambiguity results
in a similar need as when inheriting an abstract virtual function
(specifically, to define D::m()), but I think the error message is
confusing, since I do not have any abstract virtual functions defined in
the above code.
Thanks,
Greg J. Badros
gjb@cs.washington.edu
Seattle, WA USA
http://www.cs.washington.edu/homes/gjb
More information about the Gcc-bugs
mailing list