C++删除运算符混淆

标签 c++ delete-operator

<分区>

Possible Duplicate:
( POD )freeing memory : is delete[] equal to delete ?

char* pChar = new char[10];

delete pChar; // this should not work but it has same effect as 
              // delete[], WHY?
              // I know this is illegal, but why does it work?

最佳答案

它可能看起来具有相同的效果,但事实并非如此。如果您的数组类型是抽象数据类型(即类),则不会调用最后九个元素的析构函数。

关于C++删除运算符混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3144420/

相关文章:

c++ - minHessian是什么意思(Surffeaturedetector)

c++ - 在 C++ 中实现 C# "readonly"行为

php - 使用 boost 进程间库的 php exec 的共享内存和 Cloudfoundry 容器问题

c++ - delete[] 是否等于删除?

c++ - 删除数组错误

c++ - 强制隐式调用非标准删除运算符函数

c++ - boost::get vs boost::apply_visitor 从变体中获取值时

c++ - 一个对象可以告诉它的所有者删除它吗

c++ - 如何检查指针何时被删除?

c++ - mmap() 的 Linux 非持久性后备存储