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
Difference between declaration and definition of a variable.
List down the guideline that should be followed while using friend function.
What is == in programming?
int age=35; if(age>80) {Console.WriteLine("Boy you are old");} else {Console.WrieLine("That is a good age");}
How is objective c different from c++?
What are destructors?
What is the use of 'this' pointer?
Is c++ the most powerful language?
What are the advantages of using friend classes?
What is basic if statement syntax?
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?
what is C++ exceptional handling?
Difference between inline functions and macros?
What is c++ best used for?
How const int *ourpointer differs from int const *ourpointer?