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 , 928reads )
delete array; not delete [] array; simon   (470 bytes , 640reads )
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 , 287reads )
different btw 'object' and 'primitive data type' simon   (0 bytes , 342reads )
using linux/glibc? Segfault because you damaged the link list hash   (1304 bytes , 645reads )
a mistake hash   (233 bytes , 409reads )
but after icky   (103 bytes , 385reads )
The default libstdc++ operator new and delete use the libc malloc and free. hash   (86 bytes , 463reads )