Answer Posted / raj randhawa
Suppose you have two derived classes B and C that have a
common base class A, and you also have another class D that
inherits from B and C. You can declare the base class A as
virtual to ensure that B and C share the same subobject of
A.
In the following example, an object of class D has two
distinct subobjects of class L, one through class B1 and
another through class B2. You can use the keyword virtual
in front of the base class specifiers in the base lists of
classes B1 and B2 to indicate that only one subobject of
type L, shared by class B1 and class B2, exists.
For example:
class L { /* ... */ }; // indirect base class
class B1 : virtual public L { /* ... */ };
class B2 : virtual public L { /* ... */ };
class D : public B1, public B2 { /* ... */ }; // valid
Using the keyword virtual in this example ensures that an
object of class D inherits only one subobject of class L.
| Is This Answer Correct ? | 5 Yes | 0 No |
Post New Answer View All Answers
Can I learn c++ without knowing c?
what is multi-threading in C++?
Explain what happens when an exception is thrown in C++.
What is the difference between function overloading and operator overloading?
What is the difference between equal to (==) and assignment operator (=)?
What is inheritance in oop?
What is one dimensional array in c++?
Why is main function important?
Can I learn c++ as my first language?
What's the best free c++ profiler for windows?
What do you mean by translation unit?
Do the parentheses after the type name make a difference with new?
Why c++ is not a pure oop language?
Define private, protected and public access control.
What can I use instead of namespace std?