what is a virtual class?

Answer Posted / kar4you

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.

class L { /* ... */ }; // indirect base class
class B1 : virtual public L { /* ... */ };
class B2 : virtual public L { /* ... */ };
class D : public B1, public B2 { /* ... */ }; // valid

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the example of polymorphism?

550


Why is static class not inherited?

589


Which language is pure oop?

541


How long to learn object oriented programming?

553


What is encapsulation in oops?

527






What is overriding in oop?

539


How to improve object oriented design skills?

558


Who invented oop?

642


Why can't we have instance(stack) of a class as a member of the same class like eg.Class A{A obj;} as we can have self refential pointer

1603


What is pointer in oop?

528


Why do we use class in oops?

547


to find out the minimum of two integer number of two different classes using friend function

1630


any one please tell me the purpose of operator overloading

1959


Following are the class specifications: class {int a}; class {int b}; Using friend funtion,calculate the max of two objects and display it.

1996


What do you mean by variable?

565