Connecting Tech Pros Worldwide Help | Site Map

visual inheritance

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 19th, 2005, 05:31 PM
anat
Guest
 
Posts: n/a
Default visual inheritance

the following is a theoretical question, this code does not compile in
visual c++ so
my question is, considering c++ virtual inheritance mechanism how many
copies of V is D suppose to have?

class V{virtual f()};
class B1:public virtual V{...};
class B2:public virtual V{...};
class C:public B2, public virtual V{...};
class D: public virtual B1,public virtual B2,public virtual C{...},public
V{...};

thank you
Liz



  #2  
Old July 19th, 2005, 05:31 PM
White Wolf
Guest
 
Posts: n/a
Default Re: visual inheritance

anat wrote:[color=blue]
> the following is a theoretical question, this code does not compile in
> visual c++ so
> my question is, considering c++ virtual inheritance mechanism how
> many copies of V is D suppose to have?[/color]

One. That is the whole idea.

--
WW aka Attila


  #3  
Old July 19th, 2005, 05:31 PM
Pete Becker
Guest
 
Posts: n/a
Default Re: visual inheritance

anat wrote:[color=blue]
>
> the following is a theoretical question, this code does not compile in
> visual c++ so
> my question is, considering c++ virtual inheritance mechanism how many
> copies of V is D suppose to have?
>
> class V{virtual f()};
> class B1:public virtual V{...};
> class B2:public virtual V{...};
> class C:public B2, public virtual V{...};
> class D: public virtual B1,public virtual B2,public virtual C{...},public
> V{...};
>[/color]

Two. One virtual (inherited from the various bases) and one non-virtual.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
  #4  
Old July 19th, 2005, 05:31 PM
White Wolf
Guest
 
Posts: n/a
Default Re: visual inheritance

Pete Becker wrote:[color=blue]
> anat wrote:[color=green]
>>
>> the following is a theoretical question, this code does not compile
>> in visual c++ so
>> my question is, considering c++ virtual inheritance mechanism how
>> many copies of V is D suppose to have?
>>
>> class V{virtual f()};
>> class B1:public virtual V{...};
>> class B2:public virtual V{...};
>> class C:public B2, public virtual V{...};
>> class D: public virtual B1,public virtual B2,public virtual
>> C{...},public V{...};
>>[/color]
>
> Two. One virtual (inherited from the various bases) and one
> non-virtual.[/color]

Ahh! I have missed that public V. There is a {} before it, that made me
think this is the end of the declaration of the base classes. And I am not
mistaking it will do that to a compiler, too. :-)

--
WW aka Attila


  #5  
Old July 19th, 2005, 05:31 PM
Percy
Guest
 
Posts: n/a
Default Re: visual inheritance

On Mon, 15 Sep 2003 00:36:52 +0200 in comp.lang.c++ :

I took the liberty to change your example to below:

class V{
public:
V() { std::cout << "V\n"; }//virtual int f();
};
class B1:public virtual V
{
public:
B1() { std::cout << "B1\n"; }

};
class B2:public virtual V
{
public:
B2() { std::cout << "B2\n"; }
};
class C:public B2, public virtual V
{
public:
C() { std::cout << "C\n"; }
};
class D:public virtual B1,public virtual B2,
public virtual C,public V
{
public:
D() { std::cout << "D\n"; }
};


int main()
{
D d;
return 0;
}

compiler results:
warning: direct base `B2' inaccessible in `D'
due to ambiguity
warning: direct base `V' inaccessible in `D'
due to ambiguity
output:

V
B1
B2
B2
C
V
D


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.