Answer Posted / rama
The duplication of inherited members due to multiple paths can be avoided by making the common base class(ancestor class) as virtual base class..
FOR EXAMPLE
class A //grandparent
{
...
...
};
class B1:virtual public A //parent1
{
...
...
};
class B2:public virtual A //parent2
{
...
...
};
class C :public B1,public B2
{
... //only one copy of A
... //will be inherited
};
When a class is made a virtual base class, it take necessary care to see that only one copy of that class is inherited, regardless of how many inheritance paths exits between the virtual base class and a derived class.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Define pure virtual function?
Describe linkages and types of linkages?
What are the steps in the development cycle?
Is it possible to have a recursive inline function in c++?
What is the use of volatile variable?
In which header file does one find isalpha() a) conio.h b) stdio.h c) ctype.h
Do the names of parameters have to agree in the prototype, definition, and call to the function?
What is class and structure in c++?
What is vector pair in c++?
Show the declaration for a static member variable.
Is there structure in c++?
Why should you learn c++?
Why do we use iterators?
When can I use a forward declaration?
What is command line arguments in C++? What are its uses? Where we have to use this?