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.
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.
WENXUECITY.COM does not represent or guarantee the truthfulness, accuracy, or reliability of any of communications posted by other users.
Copyright ©1998-2025 wenxuecity.com All rights reserved. Privacy Statement & Terms of Use & User Privacy Protection Policy