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
Explain what are mutator methods in c++?
When one must use recursion function? Mention what happens when recursion functions are declared inline?
Why isn't sizeof for a struct equal to the sum of sizeof of each member?
What are shallow and deep copies?
Which of the following is evaluated first: a) && b) || c) !
What is static class data?
Do vectors start at 0 c++?
What is c++ & why it is used?
How is c++ used in the real world?
Why do we use constructor?
What is difference between c++ and c ++ 14?
Explain the difference between using macro and inline functions?
Explain selection sorting. Also write an example.
How can we access protected and private members of a class?
Why do we use setw in c++?