| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 609 人关注过本帖
标题:程序为什么连析构函数也不调用,还有不输出bTime,cTime两个对象
只看楼主 加入收藏
zjl138
Rank: 1
等 级:新手上路
威 望:1
帖 子:788
专家分:0
注 册:2007-11-12
收藏
 问题点数:0 回复次数:3 
程序为什么连析构函数也不调用,还有不输出bTime,cTime两个对象
程序为什么连析构函数也不调用,还有不输出bTime,cTime两个对象.
#include<iostream>
using namespace std;
class Time{
public:
Time(int hour,int minute,int second);
Time(const Time& t);
~Time();
void showTime();
private:
int hrs,mins,secs;
};
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=aTime;
cout<<"the Time stored in bTime is";
bTime.showTime();
Time cTime(bTime);
cout<<"the Time stored in cTime is";
cTime.showTime();
cout<<"End of my act!"<<endl;
return 0;
}
搜索更多相关主题的帖子: int bTime cTime 函数 hrs 
2007-11-16 22:33
beyond0702
Rank: 1
来 自: 桂 林
等 级:新手上路
帖 子:219
专家分:0
注 册:2007-11-17
收藏
得分:0 
这里出错:
Time::Time(const Time& t){
Time s(t);
hrs=s.hrs;
mins=s.mins;
secs=s.secs;
}
该为:
Time::Time(const Time& t){

hrs=t.hrs;
mins=t.mins;
secs=t.secs;
}

蝴 蝶 颤 动 了 翅 膀 !!!
2007-11-19 12:16
zjl138
Rank: 1
等 级:新手上路
威 望:1
帖 子:788
专家分:0
注 册:2007-11-12
收藏
得分:0 

行了,谢谢哦!
不过我还是不明白为什么用了 Time s(t)这个又不行!!!


i like linux...
2007-11-19 14:15
beyond0702
Rank: 1
来 自: 桂 林
等 级:新手上路
帖 子:219
专家分:0
注 册:2007-11-17
收藏
得分:0 

Time s(t) 这里面的 s 不知道从哪里来.你是想用数据成员付值,但 s 并不是 Time 里面的数据成员,如果是. 那你的写法就正确了


蝴 蝶 颤 动 了 翅 膀 !!!
2007-11-21 16:29
快速回复:程序为什么连析构函数也不调用,还有不输出bTime,cTime两个对象
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011922 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved