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 are the types of abstraction?

643


What is encapsulation with example?

673


What is the renewal class?

2260


String = "C++ is an object oriented programming language.An imp feature of oops is classes and objects".Write a pgm to count the repeated words from this scenario?

2040


What is destructor in oop?

699






Can main method override?

666


How does polymorphism work?

737


Why is polymorphism used?

672


What are classes oop?

685


What are objects in oop?

701


How do you define social class?

681


What is object in oop?

782


Why multiple inheritance is not possible?

683


What is super in oop?

694


What is an example of genetic polymorphism?

753