#include<iostream>
using namespace std;
class A
{
public:
void f(){cout<<"A::f"<<endl;}
};
class B:public A
{
};
class C:public A
{
};
class D:public B, public C
{
};
int main()
{
D d;
//d.f();//error: request for member ‘f’ is ambiguous//candidates are A::f and A::f
//d.A::f();//error: ‘A’ is an ambiguous base of ‘D’
d.B::f();//A::f
d.C::f();//A::f
//d.D::f();// error: request for member ‘f’ is ambiguous
cout<<""<<endl;
return 0;
}
//--
#include<iostream>
using namespace std;
class A
{
public:
void f(){cout<<"A::f"<<endl;}
};
class B:virtual public A
{
};
class C:virtual public A
{
};
class D:public B, public C
{
};
int main()
{
D d;
d.f();//A::f
d.A::f();//A::f
d.B::f();//A::f
d.C::f();//A::f
d.D::f();//A::f
cout<<""<<endl;
return 0;
}
//--
#include<iostream>
using namespace std;
class A
{
public:
void f(){cout<<"A::f"<<endl;}
};
class B:public A
{
public:
void f(){cout<<"B::f"<<endl;}
};
class C:public A
{
public:
void f(){cout<<"C::f"<<endl;}
};
class D:public B, public C
{
public:
void f(){cout<<"D::f"<<endl;}
};
int main()
{
D d;
d.f();//D::f
//d.A::f();//error: ‘A’ is an ambiguous base of ‘D’
d.B::f();//B::f
d.C::f();//C::f
d.D::f();//D::f
cout<<""<<endl;
return 0;
}
//--
#include<iostream>
using namespace std;
class A
{
public:
void f(){cout<<"A::f"<<endl;}
};
class B:virtual public A
{
public:
void f(){cout<<"B::f"<<endl;}
};
class C:virtual public A
{
public:
void f(){cout<<"C::f"<<endl;}
};
class D:public B, public C
{
public:
void f(){cout<<"D::f"<<endl;}
};
int main()
{
D d;
d.f();//D::f
d.A::f();//A::f
d.B::f();//B::f
d.C::f();//C::f
d.D::f();//D::f
cout<<""<<endl;
return 0;
}
//--
#include<iostream>
using namespace std;
class A
{
public:
void f(){cout<<"A::f"<<endl;}
};
class B:public A
{
public:
void f(){cout<<"B::f"<<endl;}
};
class C:public A
{
public:
void f(){cout<<"C::f"<<endl;}
};
class D:public B, public C
{
};
int main()
{
D d;
//d.f();//error: request for member ‘f’ is ambiguous//candidates are A::f and C::f and B::f
//d.A::f();//error: ‘A’ is an ambiguous base of ‘D’
d.B::f();//B::f
d.C::f();//C::f
//d.D::f();// error: request for member ‘f’ is ambiguous//candidates are A::f C::f and B::f
cout<<""<<endl;
return 0;
}
//--
#include<iostream>
using namespace std;
class A
{
public:
void f(){cout<<"A::f"<<endl;}
};
class B:virtual public A
{
public:
void f(){cout<<"B::f"<<endl;}
};
class C:virtual public A
{
public:
void f(){cout<<"C::f"<<endl;}
};
class D:public B, public C
{
};
int main()
{
D d;
//d.f();//error: request for member ‘f’ is ambiguous
d.A::f();//A::f
d.B::f();//B::f
d.C::f();//A::f
//d.D::f();//error: request for member ‘f’ is ambiguous
cout<<""<<endl;
return 0;
}
//--
#include<iostream>
using namespace std;
class A
{
public:
void f(){cout<<"A::f"<<endl;}
};
class B:public A
{
public:
void f(){cout<<"B::f"<<endl;}
};
class C:public A
{
};
class D:public B, public C
{
};
int main()
{
D d;
//d.f();//error: request for member ‘f’ is ambiguous//candidates are B::f and A::f
//d.A::f();//error: ‘A’ is an ambiguous base of ‘D’
d.B::f();//B::f
d.C::f();//A::f
//d.D::f();// error: request for member ‘f’ is ambiguous//candidates are A::f and B::f
cout<<""<<endl;
return 0;
}
//--
#include<iostream>
using namespace std;
class A
{
public:
void f(){cout<<"A::f"<<endl;}
};
class B:virtual public A
{
public:
void f(){cout<<"B::f"<<endl;}
};
class C:virtual public A
{
};
class D:public B, public C
{
};
int main()
{
D d;
d.f();//B::f
d.A::f();//A::f
d.B::f();//B::f
d.C::f();//A::f
d.D::f();// B::f
cout<<""<<endl;
return 0;
}
#include
ReplyDeleteusing namespace std;
class A
{
public:
void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
virtual void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
virtual void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
virtual void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
virtual void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
virtual void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
virtual void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
virtual void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
virtual void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
virtual void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
virtual void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
virtual void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
virtual void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
virtual void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
virtual void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
virtual void vf(){cout<<"A::vf()"<
using namespace std;
class A
{
public:
void vf(){cout<<"A::vf()"<<endl;}
};
class B:virtual public A
{
public:
void vf(){cout<<"B::vf()"<<endl;}
};
class C:public virtual A
{
public:
void vf(){cout<<"C::vf()"<<endl;}
};
class D:public B, public C
{
public:
void vf(){cout<<"D::vf()"<<endl;}
};
int main()
{
cout<<""<<endl;
D d;
d.vf();//D::vf()
d.A::vf();//A::vf()
d.B::vf();//B::vf()
d.C::vf();//C::vf()
return 0;
}