问题描述
当我使用新的一个对象的放置表单时(实际上它没有为对象分配内存空间
),我该怎么删除这个对象
相应的?
通过伪析构函数调用。
T对象;
不,你应该只明确地调用它的析构函数。
MyClass * myObj = new(somestorage)MyClass();
...
myObj->〜我的课(); // destroy
存储与''myObj'的生命周期无关,以及你如何获得它
或处理它是无关紧要的。
V
通过伪析构函数调用。
(对不起,按错键......我会继续)
T对象;
对象.~T();
new(& object)T();
但是你为什么要这样做呢?如果你不知道怎么回事,我会怀疑你不应该......
Markus
when I use the placement form new to new a object(actually it does not
alloc memory space for the object), how should I delete this object
accordingly?
By a pseudo-destructor call.
T object;
No, you should only call its destructor explicitly.
MyClass *myObj = new (somestorage) MyClass();
...
myObj->~MyClass(); // destroy
The storage is unrelated to the lifetime of ''myObj'' and how you obtain it
or dispose of it is immaterial here.
V
By a pseudo-destructor call.
(sorry, hit the wrong key... I''ll continue)
T object;
object.~T();
new (&object) T();
But why do you want to do this in the first place? If you don''t know how, I
suspect you shouldn''t...
Markus
这篇关于关于运营商新的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!