Program to illustrate the concept of ambiguity in multiple inheritance. (a) with ambiguity. (b)without ambiguity

(a) With Ambiguity:

#include<iostream>
using namespace std;
class A
{
public:
void show()
{
cout<<"Class A"<<endl;
}
};
class B
{
public:
void show()
{
cout<<"Class B"<<endl;
}
};
class C:public A,public B//multiple inheritance
{
public:
int a;
};
int main()
{
C a;
a.show();//causes inheritance
cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/";
}

Output (a):










(b) Without Ambiguity:

#include<iostream>
using namespace std;
class A
{
public:
void show()
{
cout<<"Class A"<<endl;
}
};
class B
{
public:
void show()
{
cout<<"Class B"<<endl;
}
};
class C:public A,public B//multiple inheritance
{
public:
int ab;
};
int main()
{
C a;
a.A::show();
a.B::show();
cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/";

}

Output (b):


Comments

Popular posts from this blog

Program to illustrate the concept of templates.

To create an html file to implement the concept of margin, padding using cascading style sheets.

To configure the IP address for a computer connected to LAN