关于构造析构的顺序问题
#include <iostream>using namespace std;
class A{ int x;
public:
A(int vx){x=vx;cout<<x<<"A构造 "<<endl;}
~A(){
cout<<x<<"~A析构 "<<endl;
}
};
class B { int y;
public:
B(int vy) {y=vy;cout<<y<<"B构造 "<<endl;}
~B(){cout<<y<<"~B析构 "<<endl;}
};
class C : public B { int z;
public:
A objA;
C(int vx, int vy, int vz):B(vx),objA(vy) {
z=vz;cout<<z<<"C构造 "<<endl;
}
~C(){cout<<z<<"~C析构 "<<endl;}
};
void func(int i){
static B b(i+1);
}
void main(){
A a(1);
C c(2,3,4);
func(5);
func(7);//为什么不执行这一步啊!好像和声明中的static有关,但为什么呀?
}