我偶尔遇到过这种代码 - 我怀疑创建者是/担心表删除会遍历表和“成本性能”(恕我直言,这两种方式都不会完成)......是如果不在此处使用表删除,人们可能会获得/考虑/想象任何真正的好处吗?
myClass** table = new myClass* [size];
... //some code that does not reallocate or change the value of the table pointer ;)
delete table; // no [] intentionally
最佳答案
如果您这样做,您将获得 C++ 标准所称的未定义行为 - 任何事情都可能发生。
关于c++ - 你为什么要写这样的东西? (故意不在数组上使用 delete []),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/787417/