delete array; not delete [] array;
所在版块:求学狮城 发贴时间:2005-10-30 11:15  评分:

用户信息
复制本帖HTML代码
高亮: 今天贴 X 昨天贴 X 前天贴 X 
delete [] arr;

is equivalant to

delete arr[0]; delete arr[1]; ... delete arr[k];


------------------------------------------------

defination from msdn:
The delete operator destroys the object created with new by deallocating the memory associated with the object.
------------------------------------------------

however your array is array of primative type bool


now try this

Class Bool
{
public bool myBool;
};

Bool *flag2 = new Bool[8];
delete [] flat2;
.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!


You may say I'm a dreamer
but I'm not the only one...
 相关帖子 我要回复↙ ↗回到正文
why does not "g++ -Wall" give warning message when compiling the following code? icky   (660 bytes , 932reads )
delete array; not delete [] array; simon   (470 bytes , 647reads )
do u mean icky   (132 bytes , 387reads )
no la...as simon said, object vs primitive data type sarah   (0 bytes , 390reads )
。。。。。。ok... simon   (0 bytes , 288reads )
different btw 'object' and 'primitive data type' simon   (0 bytes , 343reads )
using linux/glibc? Segfault because you damaged the link list hash   (1304 bytes , 649reads )
a mistake hash   (233 bytes , 410reads )
but after icky   (103 bytes , 385reads )
The default libstdc++ operator new and delete use the libc malloc and free. hash   (86 bytes , 464reads )