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