delete expression
来自cppreference.com
![]() |
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
和释放
[编辑] 语法
:: (可选) delete expression
|
(1) | ||||||||
:: (可选) delete [] expression
|
(2) | ||||||||
[编辑] 解释
销毁对象,构建
new
表达和释放所获得的内存区域。 expression导致的new
表达的以前调用所返回的指针的值。对于单一的分配对象的第一个版本必须使用的表达,而对数组的第二个版本,必须使用。有没有删除的的表达释放对象初始化“位置”,释放函数和析构函数必须显式调用.原文:
Destructs objects, previously constructed by
new
expression and releases the obtained memory area. The expression must result in a pointer value that was returned by previous call to the new
expression. For single allocated objects the first version of the expression must be used, whereas for arrays the second version must be used. There is no delete expression deallocating objects initialized by placement new, deallocation function and destructor must be explicitly called.该存储器被释放释放函数,要么operator delete(第一版本的表达)或operator delete[](表达式的第二个版本).
原文:
The memory is deallocated by an 释放函数, either operator delete (for the first version of the expression) or operator delete[] (for the second version of the expression).
释放函数的名称首先在本地类“类型”的范围抬起头来,只有当查找失败,全局命名空间抬起头来。
::
是delete
表达,只有全局命名空间抬起头来。该函数的原型必须看起来像下面这样:原文:
The deallocation function's name is firstly looked up in the local class type scope and only if the lookup fails, the global namespace is looked up. If
::
is present in the delete
expression, only the global namespace is looked up. The prototype of the function must look like the following: void operator delete (void *ptr); |
for the first version | |
void operator delete[](void *ptr); |
for the second version | |
这两个函数隐式声明每个翻译单元。此外,隐式实现由编译器在默认情况下,除非程序显式实现。有关更多信息,请参见这一点.
原文:
Both these functions are implicitly declared in each translation unit. Also, implicit implementations are provided by the compiler by default, unless the program has explicitly implemented them. See 这一点 for more information.