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:
|