Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Avoid Multiple Inheritance 1

Status
Not open for further replies.

abp

Programmer
Sep 14, 2000
134
FR
I have a doubt with inheritance in C++. Please look at the following class declarations;

class A {

....
};

B inherits from A
class B: public A{

...
};

C inherits from A too
class C:public A{

...
};

If I now want to declare a class D that inherits from B & C how would I do it
to avoid multiplay inheriting from A ? If I do the following ,then I guess D will
inherit multiply from A.

class D: public B, public C
{
...
};

Thanks for your help in advance

Pillai

 
Look at the virtual inheritance. The most right way is up to you, but the main idea is following:
class A
{
};
class B:virtual public A
{
};
class C:airtual public A
{
};
class D: virtual public B,virtual public C
{
}; John Fill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top