971225-egcs and virtual inheritance : ill implemented feature?
Joe Buck
jbuck@synopsys.com
Sat Jan 17 23:02:00 GMT 1998
> I'm trying to use virtual inheritance on my i586-pc-linux-glibc1 box.
> But the compilation abort cause the compiler is referring to a missing
> default-ctor.
The compiler did not abort; it issued an error message and refused to
compile your code. Furthermore, it was correct in doing so.
> The testcase below shows the problem.
The problem is that you have written invalid C++; all C++ compilers will
reject it.
> The workaround would be to define the default-ctor. But I would like to
> avoid it :-(
When you use virtual inheritance, if there is not a default constructor
all derived classes, no matter how deep, need to specify how the shared
base objects are initialized (if it is not specified the default
constructor is used). That is, even though class x02 initializes x00
with x00::x00(double), that doesn't suffice to say how class xxx will
do it, since that x00 object is shared. This means that for all
practical purposes you must provide a default constructor when you
use virtual inheritance; otherwise that shared base object is exposed
and must be explicitly set up by all derived classes at every level.
Does this mean that virtual inheritance in C++ is broken as designed?
IMHO, yes.
[ program deleted ]
To do what you want, you must write
class xxx : public x02
{
public:
xxx(double x) : x00(x), x02(x) { }
~xxx() { }
void f( ) { }
};
Does this look odd to you? It looks odd to me too, but those are the C++
rules.
More information about the Gcc
mailing list