1#include <cstdint> 2 3struct A 4{ 5 int a; 6 A (int aa): a (aa) {} 7}; 8 9struct B: public A 10{ 11 int b; 12 B (int aa, int bb): A (aa), b(bb) {} 13}; 14 15 16struct Alpha 17{ 18 virtual void x() { } 19}; 20 21struct Gamma 22{ 23}; 24 25struct Derived : public Alpha 26{ 27}; 28 29struct VirtuallyDerived : public virtual Alpha 30{ 31}; 32 33struct DoublyDerived : public VirtuallyDerived, 34 public virtual Alpha, 35 public Gamma 36{ 37}; 38 39struct Left 40{ 41 int left; 42}; 43 44struct Right 45{ 46 int right; 47}; 48 49struct LeftRight : public Left, public Right 50{ 51}; 52 53struct VirtualLeft 54{ 55 virtual ~VirtualLeft () {} 56 57 int left; 58}; 59 60struct VirtualRight 61{ 62 virtual ~VirtualRight () {} 63 64 int right; 65}; 66 67struct VirtualLeftRight : public VirtualLeft, public VirtualRight 68{ 69}; 70 71int 72main (int argc, char **argv) 73{ 74 A *a = new B(42, 1729); 75 B *b = (B *) a; 76 A &ar = *b; 77 B &br = (B&)ar; 78 79 Derived derived; 80 DoublyDerived doublyderived; 81 82 Alpha *ad = &derived; 83 Alpha *add = &doublyderived; 84 85 LeftRight gd; 86 gd.left = 23; 87 gd.right = 27; 88 unsigned long long gd_value = (unsigned long long) (std::uintptr_t)&gd; 89 unsigned long long r_value = (unsigned long long) (Right *) &gd; 90 91 LeftRight *lr = &gd; 92 Left *l = lr; 93 Right *r = lr; 94 LeftRight *lr_l = reinterpret_cast<LeftRight *>(l); 95 LeftRight *lr_r = reinterpret_cast<LeftRight *>(r); 96 Left *l_lr = reinterpret_cast<Left *>(lr); 97 Right *r_lr = reinterpret_cast<Right *>(lr); 98 99 VirtualLeftRight *vlr = new VirtualLeftRight (); 100 VirtualLeft *vl = vlr; 101 VirtualRight *vr = vlr; 102 103 return 0; /* breakpoint spot: casts.exp: 1 */ 104} 105