// multiple inheritance in C++ using namespace std; #include class A {public: virtual void f() {cout << "A.f\n";} }; class B {public: virtual void f() {cout << "B.f\n";} }; class C : public A, public B // no error here, compiler error in C#/Java {}; // no compiler error or warning so far. // Keep in mind that "main" is usually in a separate file and is // COMPILED SEPARATELY from the other classes. int main() { C *n = new C(); // no error here // n->f(); // will give compiler error about ambiguous f A *n2 = new C(); // static type A, dynamic type C n2->f(); // will print A.f: smart! B *n3 = new C(); n3->f(); // will print B.f: what did it use to figure this out? return 0; } // But what if A and B both implemented functions f and g, and I wanted // to inherit f from A and g from B????? /* Assignment: show how to simulate multiple inheritance in C# */