不僅要配對, 還要盡早釋放(一旦object 不用了, 就release.)

new 和delete的形式要一樣
如果new的對象是一個array, delete時別忘了也加上[],如下.
string *s1 = new string;
delete s1;
string *s2 = new string[100];
delete [] s2.

因為這樣, 在一個class中如有多個constructor中, 在new 同一個data member 用的形式要一樣,這樣在desctructor中, 就不會confuse.

所有跟帖: 

thanks:) -戲雨飛鷹- 給 戲雨飛鷹 發送悄悄話 戲雨飛鷹 的博客首頁 (0 bytes) () 01/23/2009 postreply 11:56:30

請您先登陸,再發跟帖!