1#include <stdio.h>
2
3class A
4{
5 public:
6 A(int _n)
7 {
8 n=_n;
9 printf("A %d\n",n);
10 }
11 int n;
12};
13
14class B
15{
16 public:
17 B(A a)
18 {
19 printf("B=%d\n",a.n);
20 }
21};
22
23class C
24{
25 public:
26 C()
27 {
28 printf("C\n");
29 }
30};
31
32class ABC
33{
34 public:
35 C c;
36 B b;
37 A a;
38
39 ABC():a(1),b(a),c()
40 {
41
42 }
43};
44
45void main()
46{
47 ABC abc;
48}
2
3class A
4{
5 public:
6 A(int _n)
7 {
8 n=_n;
9 printf("A %d\n",n);
10 }
11 int n;
12};
13
14class B
15{
16 public:
17 B(A a)
18 {
19 printf("B=%d\n",a.n);
20 }
21};
22
23class C
24{
25 public:
26 C()
27 {
28 printf("C\n");
29 }
30};
31
32class ABC
33{
34 public:
35 C c;
36 B b;
37 A a;
38
39 ABC():a(1),b(a),c()
40 {
41
42 }
43};
44
45void main()
46{
47 ABC abc;
48}
我本来想让b打印出B=1,结果却并非如此!
但如果将36,37行换过来,结果就对了!
对于程序员来讲,这点一定要注意,否则会带来奇怪的结果,而可恶的vc2005编译器竟然没有任何警告出现!