项目在内存中的位置[重复]

问题描述 投票:-2回答:1

请帮帮我。我分配内存如下(T是模板类型)

T * ptr = reinterpret_cast<T*>(operator new (sizeof(T));

之后,我想将一个元素放入此内存;如果我这样写我会写吗?

new (p) T(elem);

(元素的类型为T)

UPD:对不起,这是我忘记写操作符new的错误

c++ pointers reinterpret-cast
1个回答
1
投票

reinterpret_cast不分配内存。我不知道您对它的印象如何。

© www.soinside.com 2019 - 2024. All rights reserved.