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
What is the purpose of extern storage specifier?
Define basic type of variable used for a different condition in C++?
What is linked list in c++?
What is the c++ programming language used for?
Can malloc be used in c++?
How to declare an array of pointers to integer?
How the keyword struct is different from the keyword class in c++?
What are the advantages of using a pointer? Define the operators that can be used with a pointer.
What are the basic data types used in c++?
Who created c++?
Describe linked list using C++ with an example.
What is a stack c++?
Is it possible to have a recursive inline function in c++?
Differentiate between realloc() and free().
What do you mean by public protected and private in c++?