主题:类中关于构造函数的实现问题
#include<iostream>
using namespace std;
class clock
{
public:
clock ()
{
Hour=0;
Min=0;
Sec=0;
}
clock(int NewH,int NewM,int NewS);
void SetTime(int NewH,int NewM,int NewS);
void ShowTime();
private:
int Hour,Min,Sec;
};
void clock::SetTime(int NewH,int NewM,int NewS)
{
Hour=NewH;
Min=NewM;
Sec=NewS;
}
clock::clock(int NewH,int NewM,int NewS)
{
Hour=NewH;
Min=NewM;
Sec=NewS;
}
inline void clock::ShowTime()
{
cout<<Hour<<":"<<Min<<":"<<Sec<<endl;
}
void main()
{
clock mytime;
cout<<"show time:"<<endl;
mytime.SetTime(0,0,0);
mytime.ShowTime();
cout<<"show time:"<<endl;
mytime.SetTime(14,55,50);
mytime.ShowTime();
}
如果出去Clock::Clock( int newH , int newM , int newS)这个构造函数的实现,程序依然可以运行,没有影响,那么这个程序段的作用是什么?谢谢!
using namespace std;
class clock
{
public:
clock ()
{
Hour=0;
Min=0;
Sec=0;
}
clock(int NewH,int NewM,int NewS);
void SetTime(int NewH,int NewM,int NewS);
void ShowTime();
private:
int Hour,Min,Sec;
};
void clock::SetTime(int NewH,int NewM,int NewS)
{
Hour=NewH;
Min=NewM;
Sec=NewS;
}
clock::clock(int NewH,int NewM,int NewS)
{
Hour=NewH;
Min=NewM;
Sec=NewS;
}
inline void clock::ShowTime()
{
cout<<Hour<<":"<<Min<<":"<<Sec<<endl;
}
void main()
{
clock mytime;
cout<<"show time:"<<endl;
mytime.SetTime(0,0,0);
mytime.ShowTime();
cout<<"show time:"<<endl;
mytime.SetTime(14,55,50);
mytime.ShowTime();
}
如果出去Clock::Clock( int newH , int newM , int newS)这个构造函数的实现,程序依然可以运行,没有影响,那么这个程序段的作用是什么?谢谢!