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

Difference between declaration and definition of a variable.

926


List down the guideline that should be followed while using friend function.

845


What is == in programming?

824


int age=35; if(age>80) {Console.WriteLine("Boy you are old");} else {Console.WrieLine("That is a good age");}

1062


How is objective c different from c++?

1035


What are destructors?

783


What is the use of 'this' pointer?

1050


Is c++ the most powerful language?

784


What are the advantages of using friend classes?

916


What is basic if statement syntax?

802


If a base class is an adt, and it has three pure virtual functions, how many of these functions must be overridden in its derived classes?

841


what is C++ exceptional handling?

869


Difference between inline functions and macros?

802


What is c++ best used for?

830


How const int *ourpointer differs from int const *ourpointer?

849