What is a virtual base class?

Answer Posted / ragib nasir ahmed

A virtual base class is one in which only one copy of the
base class is inherited to the derived class.
Let us consider the classes A,B,C,D
class A
{
int a;
public:
void geta(void)
{
a=10;
}
};
class B: public virtual A
{
int b;
public:
void getb(void)
{
b=20;
}
};
class C:virtual public A
{
int c;
public:
void getc(void)
{
c=30;
}
};
class D:public B,public C
{
public:
void display(void)
{
cout<<a<<b<<c<<d;
}
};

Is This Answer Correct ?    25 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

an integer constant must have atleast one a) character b) digit c) decimal point

554


What is oops in simple words?

577


Write some differences between an external iterator and an internal iterator? Describe the advantage of an external iterator.

609


What is the difference between containment and delegation?

700


Do you know about C++ 11 standard?

631






What is heap sort in c++?

596


Explain explicit container.

633


What is destructor give example?

601


Explain how the virtual base class is different from the conventional base classes of the opps.

681


What is an advantage of polymorphism?

589


What is encapsulation oop?

574


Is enum a class?

602


What is abstraction in oop with example?

642


write a program to enter a string like"sunil is a good boy and seeking for a job" not more than 10 characters including space in one line,rest characters should b in other line.if the next line starts from in between the previous word,then print whole word to next line.

1789


How does java differ from c and c++?

535