关于函数参数,返回值与拷贝构造函数的关系!!!
#include<iostream>
using namespace std;
class Time
{
int hour,minute,second;
public:
Time():hour(0),minute(0),second(0)
{};
Time(Time &t);
void getTime();
void setTime(int h,int m,int s);
};
Time::Time(Time &t)
{
hour=t.hour;
minute=t.minute;
second=t.second;
cout<<"Notice!!! Copy constructor is being called."<<endl;
}
void Time::getTime()
{
cout<<"Now the time is"<<hour<<":"<<minute<<":"<<second<<endl;
}
void Time::setTime(int h,int m,int s)
{
if(m<0||m>59||s<0||s>59||h<0||h>23)
{
cout<<"Error!Please Check!"<<endl;
return ;
}
hour=h;
minute=m;
second=s;
}
void fun0(Time t)
{
}
Time fun1()
{
Time t;
return t;
}
void main()
{
Time time0;
time0.setTime(12,5,7);
Time time1(time0);
time1.getTime();
fun0(time0);
Time time2;
time2=fun1();
}
PS:代码没问题。Time time1(time0);这句代码调用了拷贝构造函数能够理解,请问下面的两次调用拷贝构造函数如何理解?希望能给点详细的理由!先谢谢大家了!