不仅要配对, 还要尽早释放(一旦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

请您先登陆,再发跟帖!