我正在尝试使用libstdc ++(4.6.1)在clang ++(clang 3.1版(trunk 143100))中使用std :: shared_ptr.我有一个小的演示程序:
#include <memory>
int main()
{
std::shared_ptr<int> some(new int);
std::shared_ptr<int> other(some);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
可以使用以下方法构建:
clang++ -std=c++0x -o main main.cpp
Run Code Online (Sandbox Code Playgroud)
并给出以下错误输出:
main.cpp:6:23: error: call to deleted constructor of 'std::shared_ptr<int>'
std::shared_ptr<int> other(some);
^ ~~~~
/usr/include/c++/4.6/bits/shared_ptr.h:93:11: note: function has been explicitly marked
deleted here
class shared_ptr : public __shared_ptr<_Tp>
Run Code Online (Sandbox Code Playgroud)
由于某种原因,它需要删除构造函数,因为提供了移动构造函数(这是正确的行为).但为什么它可以编译(g ++(Ubuntu/Linaro 4.6.1-9ubuntu3)4.6.1.)?有人如何解决这个问题?