1 #include <stdio.h> 2 3 static int g_next_value = 12345; 4 5 class VBase 6 { 7 public: 8 VBase() : m_value(g_next_value++) {} 9 virtual ~VBase() {} 10 void Print() 11 { 12 printf("%p: %s\n%p: m_value = 0x%8.8x\n", this, __PRETTY_FUNCTION__, &m_value, m_value); 13 } 14 int m_value; 15 }; 16 17 class Derived1 : public virtual VBase 18 { 19 public: 20 Derived1() {}; 21 void Print () 22 { 23 printf("%p: %s\n", this, __PRETTY_FUNCTION__); 24 VBase::Print(); 25 } 26 27 }; 28 29 class Derived2 : public virtual VBase 30 { 31 public: 32 Derived2() {}; 33 34 void Print () 35 { 36 printf("%p: %s\n", this, __PRETTY_FUNCTION__); 37 VBase::Print(); 38 } 39 }; 40 41 class Joiner1 : public Derived1, public Derived2 42 { 43 public: 44 Joiner1() : 45 m_joiner1(3456), 46 m_joiner2(6789) {} 47 void Print () 48 { 49 printf("%p: %s \n%p: m_joiner1 = 0x%8.8x\n%p: m_joiner2 = 0x%8.8x\n", 50 this, 51 __PRETTY_FUNCTION__, 52 &m_joiner1, 53 m_joiner1, 54 &m_joiner2, 55 m_joiner2); 56 Derived1::Print(); 57 Derived2::Print(); 58 } 59 int m_joiner1; 60 int m_joiner2; 61 }; 62 63 class Joiner2 : public Derived2 64 { 65 int m_stuff[32]; 66 }; 67 68 int main(int argc, const char * argv[]) 69 { 70 Joiner1 j1; 71 Joiner2 j2; 72 j1.Print(); 73 j2.Print(); 74 Derived2 *d = &j1; 75 d = &j2; // breakpoint 1 76 return 0; // breakpoint 2 77 } 78