关于网友提出的“ 关于类的一点小问题”问题疑问,本网通过在网上对“ 关于类的一点小问题”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: 关于类的一点小问题
描述:#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