【发布时间】:2015-03-27 02:04:01
【问题描述】:
假设我有一个类型模板参数 T。
假设我有一个std::aligned_storage,如下所示:
typename std::aligned_storage<sizeof(T), alignof(T)>::type storage;
我想将新的 T 放入 storage。
传递给placement new 运算符的符合标准的指针值/类型是什么,我如何从storage 派生它?
new (& ???) T(a,b,c);
例如:
new (&storage) T(a,b,c);
new (static_cast<void*>(&storage)) T(a,b,c);
new (reinterpret_cast<T*>(&storage)) T(a,b,c);
new (static_cast<T*>(static_cast<void*>(&storage));
以上哪项(如果有)符合要求,如果没有,更好的方法是什么?
【问题讨论】: