【发布时间】:2011-11-01 09:06:31
【问题描述】:
我正在尝试使用 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;
}
可以使用:
clang++ -std=c++0x -o main main.cpp
并给出以下错误输出:
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>
由于某种原因,它需要删除构造函数,因为提供了移动构造函数(这是正确的行为)。 但是为什么它可以与 (g++ (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1.) 一起编译?有人对如何解决这个问题有任何想法吗?
【问题讨论】:
-
/usr/include/c++/4.6通常不是 G++ 寻找其系统头文件的地方。试试g++ -v yourfile.cpp看看G++的搜索路径。 -
@Mat:不是吗? g++ 通常在
/usr/include/c++/$(version)AFAIK 中查找 c++ 标准头文件,因此 g++4.6 会在该目录中查找。从 clang++ 开始,它可能取决于它是如何编译/配置的
标签: c++ shared-ptr clang libstdc++