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
How does work in c++?
Explain the benefits of proper inheritance.
What is a string example?
How do we balance an AVL Tree in C++?
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?
What is rtti in c++?
How do you generate a random number in c++?
Can we declare a base-class destructor as virtual?
How is c++ different from java?
What do you mean by ‘void’ return type?
What is the importance of mutable keyword?
What is #include iostream h in c++?
What is a node class in c++?
What is a wchar_t in c++?
What is the exit function in c++?