【发布时间】:2012-04-19 11:08:17
【问题描述】:
在下面的代码中第3行代表什么,是类型转换的方式吗?或者什么
void someCode()
{
char memory[sizeof(Fred)]; // Line #1
void* place = memory; // Line #2
Fred* f = new(place) Fred(); // Line #3
// The pointers f and place will be equal
...
}
【问题讨论】:
-
由于对齐要求,这不起作用。
Fred类型可能需要比char更严格的对齐方式。您应该改用aligned_storage,在 C++11 和 TR1 中可用。
标签: c++ new-operator placement-new