#include #include "DerivedA.h" #include "DerivedB.h" #include "DerivedC.h" #include "DerivedD.h" #include "DerivedE.h" void Test1(); void Test2(); void Test3(); void Test4(); void Test5(); void main() { Test1(); Test2(); Test3(); Test4(); Test5(); } void Test1() { cout << "Entering Test 1" << endl; CDerivedA DerivedA; CBaseA* pBaseA; CBaseB* pBaseB; //DerivedA.foo(); //CDerivedA::foo' is ambiguous //could be the 'foo' in base 'CBaseA' of class 'CDerivedA' //or the 'foo' in base 'CBaseB' of class 'CDerivedA' DerivedA.CBaseA::foo(); DerivedA.CBaseB::foo(); pBaseA = &DerivedA; pBaseA->foo(); pBaseB = &DerivedA; pBaseB->foo(); cout << "Exiting Test 1" << endl; } void Test2() { cout << "Entering Test 2" << endl; CDerivedB DerivedB; CBaseA* pBaseA; CBaseC* pBaseC; //DerivedB.foo(); //CDerivedB::foo' is ambiguous //could be the 'foo' in base 'CBaseC' of class 'CDerivedA' //or the 'foo' in base 'CBaseB' of class 'CDerivedA' DerivedB.CBaseA::foo(); //DerivedB.CBaseC::foo(); //cannot access private member declared in class 'CBaseC' pBaseA = &DerivedB; pBaseA->foo(); pBaseC = &DerivedB; //pBaseC->foo(); //'foo' : cannot access private member declared in class 'CBaseC' cout << "Exiting Test 2" << endl; } void Test3() { cout << "Entering Test 3" << endl; CBaseA* pBaseA; CVirtualBaseD* pVirtualBaseD; CDerivedC DerivedC; //DerivedC.foo(); //CDerivedC::foo' is ambiguous //could be the 'foo' in base 'CVirtualBaseD' of class 'CDerivedA' //or the 'foo' in base 'CBaseB' of class 'CDerivedA' DerivedC.CBaseA::foo(); DerivedC.CVirtualBaseD::foo(); pBaseA = &DerivedC; pBaseA->foo(); pVirtualBaseD = &DerivedC; pVirtualBaseD->foo(); cout << "Exiting Test 3" << endl; } void Test4() { cout << "Entering Test 4" << endl; CBaseA* pBaseA; CAbstractBaseE* pAbstractBaseE; CDerivedD DerivedD; DerivedD.foo(); DerivedD.CBaseA::foo(); //DerivedD.CAbstractBaseE::foo(); //LNK2001: unresolved external symbol //"public: virtual void __thiscall CAbstractBaseE::foo(void) pBaseA = &DerivedD; pBaseA->foo(); pAbstractBaseE = &DerivedD; pAbstractBaseE->foo(); cout << "Exiting Test 4" << endl; } void Test5() { cout << "Entering Test 5" << endl; CAbstractBaseE* pAbstractBaseE; CAbstractBaseF* pAbstractBaseF; CDerivedE DerivedE; DerivedE.foo(); //CDerivedC::foo' is ambiguous //could be the 'foo' in base 'CVirtualBaseD' of class 'CDerivedA' //or the 'foo' in base 'CBaseB' of class 'CDerivedA' //DerivedE.CAbstractBaseE::foo(); //LNK2001: unresolved external symbol //"public: virtual void __thiscall CAbstractBaseF::foo(void) //DerivedE.CAbstractBaseF::foo(); //LNK2001: unresolved external symbol //"public: virtual void __thiscall CAbstractBaseE::foo(void) pAbstractBaseE = &DerivedE; pAbstractBaseE->foo(); pAbstractBaseF = &DerivedE; pAbstractBaseF->foo(); cout << "Exiting Test 5" << endl; }