| 1 | #include "a.h" |
| 2 | |
| 3 | void A::doSomething(A &anotherA) { |
| 4 | printf(format: "In A %p doing something with %d.\n" , this, m_a_value); |
| 5 | int tmp_value = anotherA.Value(); |
| 6 | printf(format: "Also have another A at %p: %d.\n" , &anotherA, tmp_value); // Break here in doSomething. |
| 7 | } |
| 8 | |
| 9 | class |
| 10 | { |
| 11 | public: |
| 12 | (int in_one, int in_two) : m_extra_one(in_one), m_extra_two(in_two) {} |
| 13 | |
| 14 | private: |
| 15 | int ; |
| 16 | int ; |
| 17 | }; |
| 18 | |
| 19 | class B : public Extra, public virtual A |
| 20 | { |
| 21 | public: |
| 22 | B (int b_value, int a_value) : Extra(b_value, a_value), A(a_value), m_b_value(b_value) {} |
| 23 | B (int b_value, int a_value, A *client_A) : Extra(b_value, a_value), A(a_value, client_A), m_b_value(b_value) {} |
| 24 | |
| 25 | virtual ~B () {} |
| 26 | |
| 27 | private: |
| 28 | int m_b_value; |
| 29 | }; |
| 30 | |
| 31 | static A* my_global_A_ptr; |
| 32 | |
| 33 | int |
| 34 | main (int argc, char **argv) |
| 35 | { |
| 36 | my_global_A_ptr = new B (100, 200); |
| 37 | B myB (10, 20, my_global_A_ptr); |
| 38 | B *second_fake_A_ptr = new B (150, 250); |
| 39 | B otherB (300, 400, second_fake_A_ptr); |
| 40 | |
| 41 | myB.doSomething(anotherA&: otherB); // Break here and get real addresses of myB and otherB. |
| 42 | |
| 43 | A reallyA (500); |
| 44 | myB.doSomething (anotherA&: reallyA); // Break here and get real address of reallyA. |
| 45 | |
| 46 | myB.doSomething(anotherA&: *make_anonymous_B()); |
| 47 | |
| 48 | take_A(a: &myB); |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |