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 main function in c++ with example?
What is a stack? How it can be implemented?
What does ios :: app do in c++?
Differentiate between structure and class in c++.
Explain Text Manipulation Routines?
What are enumerations?
Is nan a c++?
Explain some examples of operator overloading?
Is c the same as c++?
how to access grid view row?
When do we run a shell in the unix system? How will you tell which shell you are running?
Why do you use the namespace feature?
Search for: what is pair in c++?
What is the disadvantage of using a macro?
What is ofstream c++?