Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > multiple inheritance; consistency of 'virtual'

Reply
Thread Tools

multiple inheritance; consistency of 'virtual'

 
 
m0shbear
Guest
Posts: n/a
 
      03-10-2011
How come with
class A{};
class B: public A{};
class C: public virtual A, public virtual B{};

, B needs to virtual inherit A so that ambiguity in C wrt members of A
can be resolved? Is this due to subtleties of vtable generation when
MI is used?
 
Reply With Quote
 
 
 
 
Juha Nieminen
Guest
Posts: n/a
 
      03-10-2011
m0shbear <(E-Mail Removed)> wrote:
> How come with
> class A{};
> class B: public A{};
> class C: public virtual A, public virtual B{};
>
> , B needs to virtual inherit A so that ambiguity in C wrt members of A
> can be resolved? Is this due to subtleties of vtable generation when
> MI is used?


Without virtual inheritance there is an ambiguity because both B and
C inherit from A, while C also inherits from B. If you tried it without
virtual inheritance, you would get errors like:

error: 'A' is an ambiguous base of 'C'

Making C inherit from A makes little sense in this case. If you really
wanted to do that, for whatever strange reason, it would have to be done
like this:

class A {};
class B: virtual public A {};
class C: virtual public A, public B {};

However, the above is just effectively doing the same as:

class A {};
class B: public A {};
class C: public B {};

just less efficiently.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Resource (.Resx) file consistency checker prabhupr@hotmail.com ASP .Net 1 11-17-2006 12:36 AM
Resource (.Resx) file consistency checker prabhupr@hotmail.com ASP .Net 0 03-07-2006 05:14 PM
Maintain Consistency With ASP.NET Templates =?Utf-8?B?VkIgQ29kZXI=?= ASP .Net 1 02-13-2006 10:38 PM
Consistency? decius The Lounge 3 06-26-2005 05:28 PM
Consistency Check. Lee Davison Computer Support 2 09-02-2004 05:12 PM



Advertisments