【发布时间】:2012-03-19 10:50:39
【问题描述】:
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
class A
{
public:
std::string s;
A()
{
s = "string";
new(this)A(*this);
}
};
int main()
{
A a;
std::cout<<a.s;
return 0;
}
我在输出中得到空字符串。 C++ 标准对此类行为有何规定?
【问题讨论】:
-
噢,我现在真的需要喝咖啡。
-
我在 GCC 4.5 的输出中得到了“字符串”
-
这是:
new(this)A(*this);invoking copy constructor inside other constructor? -
stdlib.h=>cstdlib但无论如何这里都不需要标题。
标签: c++ placement-new