1#include "a.h"
2
3void 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
9class Extra
10{
11public:
12 Extra (int in_one, int in_two) : m_extra_one(in_one), m_extra_two(in_two) {}
13
14private:
15 int m_extra_one;
16 int m_extra_two;
17};
18
19class B : public Extra, public virtual A
20{
21public:
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
27private:
28 int m_b_value;
29};
30
31static A* my_global_A_ptr;
32
33int
34main (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

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of lldb/test/API/lang/cpp/dynamic-value/pass-to-base.cpp