/****************************************************************************\ * * * Test program that demonstrates bug with virtual base classes and pointer * * to member * * * * Author: Ian Farquharson (ifarquha@ihug.co.nz) * * * \****************************************************************************/ #include #include // Class declarations ======================================================== class Base1 { public: virtual ~Base1(void); }; class Base2 { public: virtual ~Base2(void); virtual void Click(void); }; class Test1: public Base1, public Base2 // NB: non-virtual { public: virtual ~Test1(void); virtual void Click(void); }; class Test2: virtual public Base1, virtual public Base2 // NB: virtual { public: virtual ~Test2(void); virtual void Click(void); }; // Class implementation ====================================================== Base1::~Base1(void) { } Base2::~Base2(void) { } void Base2::Click(void) { printf("void Base2::Click(void)\n"); } Test1::~Test1(void) { } void Test1::Click(void) { printf("void Test1::Click(void)\n"); } Test2::~Test2(void) { } void Test2::Click(void) { printf("void Test2::Click(void)\n"); } // RunTest1 demonstrates a class using multiple inheritence ================== typedef void (Test1::*Test1Proc)(void); void RunTest1(void) { Test1 test; printf("Calling Test1::Click directly.\n"); test.Click(); printf("Calling Test1::Click through pointer to member.\n"); Test1Proc proc = &Test1::Click; (test.*proc)(); } // RunTest2 demonstrates a class using multiple virtual inheritence ========== typedef void (Test2::*Test2Proc)(void); void RunTest2(void) { Test2 test; printf("Calling Test2::Click directly.\n"); test.Click(); printf("Calling Test2::Click through pointer to member.\n"); Test2Proc proc = &Test2::Click; (test.*proc)(); } // main ====================================================================== int main(int, char* []) { RunTest1(); RunTest2(); return 0; }