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
What are the benefits of operator overloading?
What is the difference between a declaration and a definition?
What is insertion sorting?
How can you quickly find the number of elements stored in a dynamic array? Why is it difficult to store linked list in an array?
What is encapsulation in oops?
Describe protected access specifiers?
What is the difference between Stack and Queue in C++?
What is difference between abstraction and encapsulation?
write string class as your own class in java without using any built-in function
What is a volatile variable in c++?
Can we call a virtual function from a constructor?
What is the use of namespace std in C++?
Is atoi safe?
What is the role of static keyword for a class member variable?
What does iomanip mean in c++?