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 an html tag?
the first character in the variable name must be an a) special symbol b) number c) alphabet
What is enum class in c++?
What is the benefit of c++?
Differentiate between late binding and early binding.
What are the types of array in c++?
Will c++ be replaced?
How should a contructor handle a failure?
What you know about structures in C++?
What is a manipulative person?
What do you understand by zombie objects in c++?
How can you quickly find the number of elements stored in a dynamic array? Why is it difficult to store linked list in an array?
How the memory management in vectors are being done. What happens when the heap memory is full, and how do you handle it ?
What is the use of turbo c++?
What is scope resolution operator in c++ with example?