对类成员初始化顺序的困惑
#include<iostream.h>#include<string.h>
int nextStudentID=0;
class StudentID
{
public:
StudentID()
{
value=++nextStudentID;
cout<<"Assigning student id"<<value<<endl;
}
~StudentID()
{
--nextStudentID;
cout<<"Destructing id"<<value<<endl;
}
protected:
int value;
};
class Student
{
public:
Student(char* pName="noName")
{
cout<<"Constructing student "<<pName<<endl;
strcpy(name,pName);
name[sizeof(name)-1]='\0';
}
protected:
char name[20];
StudentID id;
};
int main()
{
Student s("Marry");
return 0;
}
运行结果为:Assigning student id 1
Constructing student Marry
Destructing id 1
我对此程序的执行顺序不太理解,请高手指点一下!