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 difference between structure and class?
How can I learn c++ easily?
Why #include is used?
Why is polymorphism useful?
Can non graphic characters be used and processed in C++?
What is an adaptor class in c++?
What is a multiset c++?
What is the difference between multiple and multilevel inheritance in c++?
What is the use of main function in c++?
Why c++ is not a pure oop language?
Explain the uses of static class data?
What is the use of string in c++?
Describe Trees using C++ with an example.
What do you mean by delegate? Can a user retain delegates?
What is c++ & why it is used?