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
What are vectors used for in c++?
Does a derived class inherit or doesn't inherit?
what is the use of void main() in C++ language?
what does the following statement mean? int (*a)[4]
What are the effects after calling the delete this operator ?
What is the c++ programming language used for?
Out of fgets() and gets() which function is safe to use and why?
How can we access protected and private members of a class?
Can you please explain the difference between overloading and overriding?
Which bitwise operator is used to check whether a particular bit is on or off?
What is a driver program?
What is the disadvantage of using a macro?
Explain queue. How it can be implemented?
Are strings mutable in c++?
Are c and c++ similar?