In the following program, obviously there is a memory leak. Other than that, I see memory newed in the main function is deleted twice. When I ran it, it did not crash however. Anybody can explain it? Thanks #include class Ctest { public: Ctest(){} ~Ctest(){} double m_value[200]; }; void function(Ctest* test) { delete test; test = new Ctest(); } int main() { Ctest* t = new Ctest(); function(t); delete t; return 0;
d*h
6 楼
1,package description:Becker FAR/BEC 08 REG/AUD 09 complete package, Textbooks, Lecture DVD, Data CD (PassMaster), Course CD. 2,出版商:Becker 3,新旧程度: Used 4,交换、出售、求购的价格: Negotiable. 5,邮寄方式: Your choice. 6,买卖双方谁承担邮寄损失(required): Buyer 7,其它补充说明:附送全套 Becker final exams. 8,广告的有效期: Till sold 9,我的联系方式: d****[email protected] 10,物品来源 (required): Purchased from Becker. 11,交易双方声明:materials in question are legal publication。出售购买考试 软件也许会侵犯版权法,将面临最高$10,000罚款和一年监禁。双方确认无上述违法行 为,否则,自行承担一切相关责任。MIT及其Accounting版不承担任何责任。
【在 f******y 的大作中提到】 : In the following program, obviously there is a memory leak. Other than that, : I see memory newed in the main function is deleted twice. When I ran it, it : did not crash however. Anybody can explain it? Thanks : #include : class Ctest { : public: : Ctest(){} : ~Ctest(){} : double m_value[200]; : };
b*o
10 楼
same as above. please contact me through MITBBS
O*C
11 楼
我不是通过报税软件e-file的,而是手填的。 而且是1040NR,可以通过4056-T要到一份transcript么? 我主要是想把当年Katrina飓风造成的损失抵一些税。 不知道通过4056-T要到的transcript上的信息是否够填1040X? FORM 4056要收57刀的费用,觉得太贵了。 谢谢指教!
it is deleted twice, since the memory allocated in function() did not get re turned. so it is undefined behaviour. quite often it will lead to program crash. but quite as often it will not lead to crash. thus it is undefined.
【在 r****t 的大作中提到】 : 你 new 了两次, delete 了两次吧 : : that, : it
interesting, try this void function(Ctest* test) { delete test; Ctest* test1 = new Ctest(); test = new Ctest(); delete test1; } you may see why...
that, it
【在 f******y 的大作中提到】 : In the following program, obviously there is a memory leak. Other than that, : I see memory newed in the main function is deleted twice. When I ran it, it : did not crash however. Anybody can explain it? Thanks : #include : class Ctest { : public: : Ctest(){} : ~Ctest(){} : double m_value[200]; : };