C++类成员初始化方法
1.Initializer(初始化器)
例
class Time
{
public:
Time();
private:
int hour;
int minute;
};
//调用构造函数时,会为hour,minute赋初始值0
Time::Time():hour(0),minute(0)
{
}
2.在构造函数里进行赋值
class Time
{
public:
Time(int h,int m)
{
hour = h;
minute = m;
}
private:
int hour;
int minute;
};