Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What is Virtual Inheritance?

Answer Posted / achal ubbott

The concept of virtual inheritance was evolved to avoid
ambiguity/duplication.

e.g.
class base
{
int value;
};
now we do some multiple inheritance
class A:public base {};
class B:public base {};

Now value is member to both the classes A and B.
Lets have a class C that inherits from both A and B.
class C:public A, public B {};

Now should that mean that C have 2 copies of value as its
data member? Yes and this leads to ambiguity.
So do like this

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

Is This Answer Correct ?    5 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How does work in c++?

1034


Explain the benefits of proper inheritance.

1097


What is a string example?

1031


How do we balance an AVL Tree in C++?

1101


If we want that any wildcard characters in the command line arguments should be appropriately expanded, are we required to make any special provision? If yes, which?

1458


What is rtti in c++?

1072


How do you generate a random number in c++?

1042


Can we declare a base-class destructor as virtual?

971


How is c++ different from java?

1005


What do you mean by ‘void’ return type?

1009


What is the importance of mutable keyword?

991


What is #include iostream h in c++?

1103


What is a node class in c++?

1036


What is a wchar_t in c++?

1073


What is the exit function in c++?

955