标题:类的对象作为函数参数而出现的问题
取消只看楼主
幽园香客
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:231
专家分:142
注 册:2006-2-27
结帖率:50%
 问题点数:0 回复次数:1 
类的对象作为函数参数而出现的问题
将类的对象作为函数参数,测试时出现了奇怪的结果。
#include "iostream.h"
class test
{
public:
test(){cout<<"test construction"<<endl;}
~test(){cout<<"test destruction"<<endl;}
}
class A
{
public:
A(test s){cout<<"A construction"<<endl;}
~A(){cout<<"A destruction"<<endl;}
}
void main()
{
test a;
A(a);
return 0;
}
结果: test construction
A construction
test destruction //注意此行,多调用一次test析构函数
A destruction
test destrcution
这是怎么回事?难道析构函数和构造函数还不是配对出现的?哪位兄弟知道,谢谢了
搜索更多相关主题的帖子: 函数 参数 对象 
2007-03-24 22:06
幽园香客
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:231
专家分:142
注 册:2006-2-27
得分:0 
谢谢楼上的几位版主!呵呵,昨天晚上可能是糊涂了,竟然忘了考虑默认拷贝构造函数了。

[此贴子已经被作者于2007-3-25 10:29:43编辑过]



做个有用的人!
2007-03-25 10:28



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-126538-1-1.html




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

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