1 #include <iostream> 2 #include <string> 3 4 int *new_int(int val) { 5 return new int(val); 6 } 7 8 struct baz 9 { 10 int h; 11 int k; 12 baz(int a, int b) : h(a), k(b) {} 13 }; 14 15 struct bar 16 { 17 int i; 18 int* i_ptr; 19 baz b; 20 baz& b_ref; 21 bar(int x) : i(x),i_ptr(new int(x+1)),b(i+3,i+5),b_ref(b) {} 22 }; 23 24 struct foo 25 { 26 int a; 27 int* a_ptr; 28 bar b; 29 30 foo(int x) : a(x), 31 a_ptr(new_int(x+1)), 32 b(2*x) {} 33 34 }; 35 36 foo *new_foo(int x) { 37 return new foo(x); 38 } 39 40 41 int main(int argc, char** argv) 42 { 43 foo foo1(12); 44 foo foo2(121); 45 foo * newd_foo = new_foo(1); 46 delete newd_foo; 47 foo2.a = 7777; // Stop here 48 *(foo2.b.i_ptr) = 8888; 49 foo2.b.b.h = 9999; 50 51 *(foo1.a_ptr) = 9999; 52 foo1.b.i = 9999; 53 54 int numbers[5] = {1,2,3,4,5}; 55 56 return 0; // Done initializing 57 58 } 59