#include<iostream>
using namespace std;
class Time{
public:
Time();
Time(int hour,int minute,int second);
Time(const Time& t);
~Time();
void showTime();
private:
int hrs,mins,secs;
};
Time::Time()
{ hrs=0;mins=0;secs= 0; }
Time::Time(int hour,int minute,int second){
hrs=hour;
mins=minute;
secs=second;
}
Time::Time(const Time& t){
Time s(t);
hrs=s.hrs;
mins=s.mins;
secs=s.secs;
}
Time::~Time()
{cout<<"Destruction is called"<<endl;}
void Time::showTime()
{cout<<hrs<<":"<<mins<<":"<<secs<<endl;}
int main(){
cout<<"<<<Object Tnitiallizations uing the\''copy constructor\">>>"<<endl;
Time aTime(10,20,30);
cout<<"the Time stored in aTime is";
aTime.showTime();
Time bTime;
bTime=aTime;
cout<<"the Time stored in bTime is";
bTime.showTime();
Time cTime;
cTime=bTime;
cout<<"the Time stored in cTime is";
cTime.showTime();
cout<<"End of my act!"<<endl;
return 0;
}
把它Time bTime;bTime=aTime;Time cTime;cTime=bTime;变成Time bTime(aTime);Time cTime(bTime)或者Time bTime=aTime;Time cTime=bTime为什么运行得不到想要结果了那?
赋值问题