有人可以告诉我,下面的unique_ptr初始化有什么问题吗?
int main()
{
unique_ptr<int> py(nullptr);
py = new int;
....
}
g ++ -O2 xxx.cc -lm -o xxx -std = c ++ 11说:
error: no match for ‘operator=’ (operand types are ‘std::unique_ptr<int>’ and ‘int*’)
py = new int;
^
在做
unique_ptr<int> px(new int);
效果很好。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句