Thread View: comp.std.c++
2 messages
2 total messages
Started by richard henderson~
Thu, 18 Apr 1991 23:37
Pure functions and derived classes
Author: richard henderson~
Date: Thu, 18 Apr 1991 23:37
Date: Thu, 18 Apr 1991 23:37
38 lines
1227 bytes
1227 bytes
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
Re: Pure functions and derived classes
Author: Ilan CARON
Date: Mon, 29 Apr 1991 15:39
Date: Mon, 29 Apr 1991 15:39
30 lines
1755 bytes
1755 bytes
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)
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads