#include <iostream.h>
class A{
public:
A(int x=1){
i=x;
cout<<"A()"<<i<<endl;
}
~A(){
cout<<"~A()"<<i<<endl;
}
private:
int i;
};
class B{
public:
static A a1;
static A a2;
B(){
cout<<"B()"<<endl;
}
~B(){
cout<<"~B()"<<endl;
}
};
A a3(6);
A B::a1=*(new A);
A B::a2=*(new A);
A a4(7);
void main(){
//B b;
cout<<"main begin."<<endl;
}
结论:不管是全局变量,还是类内部的静态成员变量,编译器编译的时候是按照它们在文件中的声明顺序确定的。依次进行初始化。