您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> C/C++ >> 关于类的一点小问题

关于类的一点小问题

来源:网络整理     时间:2016/8/29 6:51:09     关键词:

关于网友提出的“ 关于类的一点小问题”问题疑问,本网通过在网上对“ 关于类的一点小问题”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题: 关于类的一点小问题
描述:

#include 
using namespace std;
class A
{
public:
A()
{
cout << "constructor" << endl;
}
A(const A & B)
{
cout << "copy constructor" << endl;
}
~A()
{
cout << "Destroyer" << endl;
}
};
A f()
{
A a;
return a;
}
int main()
{
A b;
b = f();
A c=b;
return 0;
}
/*
constructor
constructor
copy constructor
Destroyer
Destroyer      这个析构函数是析构谁的,还有能不能用某个语句显示出是哪个
                       作用域内调用的这个构造/析构函数呢?
copy constructor          
Destroyer
Destroyer
请按任意键继续. . .
*/

解决方案1:

别忘f()的局部对象。 


以上介绍了“ 关于类的一点小问题”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3653479.html

相关图片

相关文章