in file "abc.h" /************************************************/ struct XXX { int *xyz; }; class ABC { private: public: XXX *a; void sth(); ABC(); ~ABC(); }; /**********************************************/ /**********************************************/ in file "abc.cpp" /**********************************************/ #include using namespace std; #include "abc.h" ABC::ABC() { a = NULL; } ABC::~ABC() { if
C*l
3 楼
【 以下文字转载自 Business 讨论区 】 发信人: ChrisPaul (大黄蜂), 信区: Business 标 题: paper under second round review是什么意思? 发信站: BBS 未名空间站 (Mon Jan 12 17:23:42 2009) 第一次投被据,修改以后又投的是吗?
x*t
4 楼
问题是。。。。 请问我怎样在构造函数中初始以及和析构函数中delete这个xyz? 多谢!!!!
z*e
5 楼
Revised and Resubmitted
r*r
6 楼
why not just say: XXX::XXX() : xyz(0) {} XXX::~XXX() { delete xyz; }
c*b
7 楼
我的理解是,投出去叫under review,如果被允许修改,在按照referee的意思修改后 再送到同一journal叫under second round review。
【在 C*******l 的大作中提到】 : 【 以下文字转载自 Business 讨论区 】 : 发信人: ChrisPaul (大黄蜂), 信区: Business : 标 题: paper under second round review是什么意思? : 发信站: BBS 未名空间站 (Mon Jan 12 17:23:42 2009) : 第一次投被据,修改以后又投的是吗?
x*t
8 楼
oh....thanks...
【在 r*********r 的大作中提到】 : why not just say: : XXX::XXX() : xyz(0) {} : XXX::~XXX() { delete xyz; }
多谢各位!! 这样的话,“abc.h”不变,而“abc.cpp”就可以写成: #include using namespace std; #include "abc.h" ABC::ABC() { a = NULL; } ABC::~ABC() { if(a) delete[]a; } XXX::XXX() { xyz = NULL; } XXX::~XXX() { if(xyz) delete[]xyz; } void ABC::sth() { int num_1; cin>>num_1; int num_2; cin>>num_2; a = new XXX[num_1]; for (int i=0;i{ a[i].xyz = new int[num_2]; } } 请问在运行完之后,程序如何析构?应该先delete掉xyz还是a? C++自己会如何
r*r
18 楼
if you create an ABC object on stack, no need to do anything: when that object goes out of scope, it will be destructed automatically, which again triggers all XXX objects' destructors one after another.
actually, standard says "The macro NULL is an implementation-defined C++ null pointer constant in this International Standard.1) 1) Possible definitions include 0 and 0L, but not (void*)0." so 0 is (one of) "possible definition"...
【在 f*******y 的大作中提到】 : 我查了一下 : C++真的把NULL=0写入标准了
t*n
22 楼
XXX::~XXX() { delete [] xyz; }
【在 r*********r 的大作中提到】 : why not just say: : XXX::XXX() : xyz(0) {} : XXX::~XXX() { delete xyz; }