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
Why cstdlib is used in c++?
Comment on c++ standard exceptions?
What are the two shift operators and what are their functions?
What size is allocated to the union variable?
How is c++ different from java?
What do you mean by “this” pointer?
Explain rethrowing exceptions with an example?
Explain how we implement exception handling in c++?
What is using namespace std in cpp?
What sorting algorithm does c++ use?
Why c++ is called oop?
What is c++ coding?
What things would you remember while making an interface?
What is operators in c++?
What jobs can you get with a c++ certification?