st12a@menudo.uh.edu (richard henderson~) (04/19/91)
In the following construction: struct Base { virtual int func_a() = 0; virtual int func_b() = 0; virtual int func_c() = 0; }; struct Mid_a : virtual public Base { virtual int func_a(); virtual int func_b() = 0; virtual int func_c() = 0; }; struct Mid_b : virtual public Base { virtual int func_a() = 0; virtual int func_b(); virtual int func_c() = 0; }; struct Der : public Mid_a, public Mid_b { virtual int func_c(); }; both BC++ and g++ complain that the pure functions Mid_a::func_b() and Mid_b::func_a() are not overridden. What is the proper way to declare this construction? It seemed to me that Mid_a::func_a() should override Mid_b::func_a() and vice-versa. thanks in advance, richard~ st12a@menudo.uh.edu richard@stat.tamu.edu
ilanc@microsoft.UUCP (Ilan CARON) (04/29/91)
In article <1991Apr18.233753.26738@menudo.uh.edu> st12a@menudo.uh.edu (richard henderson~) writes: > > [ hierarchy deleted] >both BC++ and g++ complain that the pure functions Mid_a::func_b() and >Mid_b::func_a() are not overridden. > >What is the proper way to declare this construction? It seemed to me >that Mid_a::func_a() should override Mid_b::func_a() and vice-versa. > [This cropped up a while ago...] The problem is that Base is a *virtual* base of class Der. I.e. there is only one instance of Base in instances of Der. Consider now Base* pointers. Note that the true type of instances referenced by such pointers could be only Der (since its base classes are all abstract and as such non-instantiable"). The obvious question then is "what should the contents of the vtable slot for say func_b() be (in the vtable pointed to by Base* pointers)?" Well... it's not clear. Should it be &Mid_b::func_b()? (which is a real address) or should it be some indication that the method is a pure virtual (corresponding to the pure virtual in class Mid_a)? In other words, an ambiguity. And as such C++ doesn't let you declare such classes (i.e. Der) since there's no way to construct such an animal. --ilan caron (uw-beaver!microsoft!ilanc)