由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 请教这个程序里用到了什么constructor啊?有几个copy constructor?
相关主题
为什么foo1可以而foo2不行?一个古怪的C程序运行错误。
菜鸟求教,一个c++的困惑[C++ boost::interprocess] 讨论贴
菜鸟请教smart pointer关于c++的constructor的面试题
定义的struct数组很大时,为什么会出现奇怪的大数字?请教一个基本的constructor和destrcutor问题
C++菜问: 怎么这样也可以?一个c++ constructor的问题, thanks
请问一个exception题目一个读用户输入的小问题
A aimple C++ questionint i:1
没有经过构造函数???请问C++中局部未使用的变量在优化的时候会去掉么?
相关话题的讨论汇总
话题: myclass话题: destructor话题: int话题: num
进入Programming版参与讨论
1 (共1页)
J**********y
发帖数: 1891
1
有几个destructor呢?
我怎么老是数不对?谢谢。
// mytry1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
using namespace std;
class myclass
{
public:
int num;
myclass(int a)
{
num=a;
}
myclass(const myclass & a)
{
num=a.num;
cout << "copy constructor ... " << endl;
}

~myclass()
{
cout << "destructor ... " << endl;

}
};
int _tmain(int argc, _TCHAR* argv[])
{
myclass x(5);
x=10;
x=myclass(20);
myclass y(10);
y=x;
myclass z(y);
return 0;
}
M**********n
发帖数: 432
2
Constructor, copy constructor and assignment operator.
Destructor called 5 times since there are 5 objects created.

【在 J**********y 的大作中提到】
: 有几个destructor呢?
: 我怎么老是数不对?谢谢。
: // mytry1.cpp : Defines the entry point for the console application.
: //
: #include "stdafx.h"
: #include
: using namespace std;
: class myclass
: {
: public:

a***y
发帖数: 2803
3
visual studio 2008的运行结果
destructor ...
destructor ...
copy constructor ...
destructor ...
destructor ...
destructor ...

【在 J**********y 的大作中提到】
: 有几个destructor呢?
: 我怎么老是数不对?谢谢。
: // mytry1.cpp : Defines the entry point for the console application.
: //
: #include "stdafx.h"
: #include
: using namespace std;
: class myclass
: {
: public:

1 (共1页)
进入Programming版参与讨论
相关主题
请问C++中局部未使用的变量在优化的时候会去掉么?C++菜问: 怎么这样也可以?
还是咱们这儿,亲。请问一个exception题目
请大侠评点一下我这个C++多重继承的程序。。。写得对不对啊。A aimple C++ question
我这个C++程序有没有什么问题啊?请指点。。。谢谢。。。没有经过构造函数???
为什么foo1可以而foo2不行?一个古怪的C程序运行错误。
菜鸟求教,一个c++的困惑[C++ boost::interprocess] 讨论贴
菜鸟请教smart pointer关于c++的constructor的面试题
定义的struct数组很大时,为什么会出现奇怪的大数字?请教一个基本的constructor和destrcutor问题
相关话题的讨论汇总
话题: myclass话题: destructor话题: int话题: num