Connecting Tech Pros Worldwide Help | Site Map

visual inheritance

  #1  
Old July 19th, 2005, 06:31 PM
anat
Guest
 
Posts: n/a
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, 06:31 PM
White Wolf
Guest
 
Posts: n/a

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, 06:31 PM
Pete Becker
Guest
 
Posts: n/a

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, 06:31 PM
White Wolf
Guest
 
Posts: n/a

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, 06:31 PM
Percy
Guest
 
Posts: n/a

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


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
VS.NET 2005, visual inheritance, and MustInherit Ray Cassick \(Home\) answers 2 November 23rd, 2005 04:37 AM
MasterPages or Web Visual Inheritance (ASP.Net 1.1)? VR answers 6 November 18th, 2005 07:05 PM
Visual Inheritance with ASP.NET Gopal Prabhakaran answers 10 November 18th, 2005 03:06 AM
IsPostBack value incorrect using Server.Transfer in Front Controller plus Visual Inheritance Mr Wizard answers 2 November 18th, 2005 02:25 AM
Problems with Visual Inheritance & Menus Matt answers 2 July 17th, 2005 10:09 PM