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 are the stages in the development cycle?
How can you specify a class in C++?
How many namespaces are there in c++?
What is the header file for setw?
What is static class data?
What are c++ files?
Explain differences between alloc() and free()?
Why we use #include iostream in c++?
What is #include cstdlib in c++?
What is a stack c++?
C is to C++ as 1 is to a) What the heck b) 2 c) 10
Can we use struct in c++?
How does code-bloating occur in c++?
Can you explicitly call a destructor on a local variable?
Suppose that data is an array of 1000 integers. Write a single function call that will sort the 100 elements data [222] through data [321].