-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvector2array.cpp
More file actions
46 lines (40 loc) · 776 Bytes
/
Copy pathvector2array.cpp
File metadata and controls
46 lines (40 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <vector>
using namespace std;
struct BASE {
int x;
};
struct BASE2 {
int y;
};
class Test {
vector<BASE*> g_base;
public:
vector<BASE*>& test() {
BASE * a = new BASE();
a->x = 1;
g_base.push_back(a);
return g_base;
}
};
void test3(BASE2** base2) {
printf("test3 %p = %d\n",base2, base2[0]->y);
}
BASE2** test2(Test* t) {
vector<BASE*>& base = t->test();
BASE2** base2 = (BASE2**)&base[0];
printf("test2 %p = %d\n", base2, base2[0]->y);
test3(base2);
return base2;
}
int main()
{
Test t;
BASE2 ** base2 = test2(&t);
try {
printf("main %p %d\n", base2, base2[0]->y);
}catch (exception e) {
printf(e.what());
}
return 0;
}