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