/*A demo program showing Virtual Base Class implementation*/
#include<iostream>
#include<cstdlib>
using namespace std;
class O
{
public:
int commonValue;
};
class A1:virtual public O
{
public:
A1()
{
commonValue=10;
}
};
class B1:virtual public O
{
public:
B1()
{
commonValue=20;
}
};
class C1:public A1,public B1
{
public:
void fx()
{
cout<<commonValue;//prints the value 20; Exchange the order of Inheritance A1 and B1 in C1; Output den wld b 10
}
};
int main()
{
C1 see;
see.fx();
system("pause");
}
#include<iostream>
#include<cstdlib>
using namespace std;
class O
{
public:
int commonValue;
};
class A1:virtual public O
{
public:
A1()
{
commonValue=10;
}
};
class B1:virtual public O
{
public:
B1()
{
commonValue=20;
}
};
class C1:public A1,public B1
{
public:
void fx()
{
cout<<commonValue;//prints the value 20; Exchange the order of Inheritance A1 and B1 in C1; Output den wld b 10
}
};
int main()
{
C1 see;
see.fx();
system("pause");
}
0 comments:
Post a Comment