multiple-inh/ambiguities/amb-2.cc - Ambiguity resolution in the client of C. | Lecture 5 - slide 18 : 40 Program 2 |
// How to use the scope resolution operator to resolve the ambiguity // from a client of class C. #include <iostream> #include <string> using namespace std; class A { public: int data; int operation(){ cout << "A: operation" << endl; return data; } }; class B { public: int data; int operation(){ cout << "B: operation" << endl; return data; } }; class C: public A, public B{ }; int f(C* c){ int r1 = c->A::operation(), r2 = c->B::operation(); return r1 + r2; } int main(){ f(new C()); // OUTPUT: // A: operation // B: operation }