上面一节已经探究出this指针的辨别,由this指针就可以看到类的内容。在这里,就由this指针来看一下类的成员变量是如何排列。
先看一个例子
1 #include <stdio.h>
2 class xuzhina_dump_c06_s2
3 {
4 private:
5 short m_c;
6 char m_d;
7 int m_e;
8
9 public:
10 xuzhina_dump_c06_s2( int a, int b )
11 {
12 m_c = (short)(a + b);
13 m_d = 'd';
14 m_e = a - b;
15 }
16 void print( )
17 {
18 printf( "member %d, %c, %d\n", m_c, m_d, m_e );
19 }
20 };
21
22 int main()
23 {
24 xuzhina_dump_c06_s2 test( 2, 3 );
25 test.print();
26 return 0;
27 }
更多内容请关注微信公众号“debugeeker", 链接为https://mp.weixin.qq.com/s/TrTXu6trJIhMAiSfpS9KFg