Apple and shared_ptr
Apple and shared_ptr
我似乎在这里错过了一些东西。我从boost::shared_ptr
搬到了std::shared_ptr
. 早在 2000 年代中期,shared_ptr
就是 TR1 的一部分,2012 年应该可以在任何地方使用。
尝试在Apple下使用shared_ptr
会给我带来大量未定义的引用:
SecureArray.h:26:12: error: no member named 'shared_ptr' in
namespace 'std'
using std::shared_ptr;
~~~~~^
SecureArray.h:27:12: error: no member named 'tr1' in namespace
'std'
using std::tr1::shared_ptr;
~~~~~^
SecureArray.h:487:5: error: unknown type name 'shared_ptr'
shared_ptr<SecureVector> m_vector;
典型的编译器命令如下(GCC 和 Clang 都失败):
clang++ -g2 -ggdb -O0 -fcatch-undefined-cxx0x-behavior
-DSAFEINT_DISALLOW_UNSIGNED_NEGATION=1 -pipe -std=c++0x -Wall -Wextra
-Wno-unused-parameter -Wno-tautological-compare
-I. -I./esapi -I./deps -I/usr/local/include -I/usr/include -fpic
-c src/DummyConfiguration.cpp -o src/DummyConfiguration.o
我试图将其包含如下(我相信我需要调整它,但我不记得C++语法说"看这里,或看那里"):
#include <memory>
using std::shared_ptr;
using std::tr1::shared_ptr;
苹果的手册页没有出现任何东西:
$ man shared_ptr
No manual entry for shared_ptr
$ man -k shared_ptr
shared_ptr: nothing appropriate
我安装了Mac OS X 10.8(完全修补),Xcode(完全修补)和命令行工具。
那么如何在苹果平台上使用std::shared_ptr呢?
#include <tr1/memory>
将使用libstdc++与任一编译器一起使用。或者,与叮当:
#include <memory>
using std::shared_ptr;
并使用c++ -std=c++11 -stdlib=libc++ ...
编译.我不知道为什么 Clang 默认使用 libstdc++;大概是为了 GCC 兼容性。
找不到手册页,因为 libstdc++ 没有手册页。有帮助,不是吗。源代码分发中有 HTML 文档。
相关文章:
- CLANG 编译器 说:变量"PTR"可能未初始化
- 在以唯一ptr为值的C++映射中,动态内存何时会被销毁
- 将 ptr 传递给 ptr 到 A 作为参数传递给 A 的函数是不好的做法吗?
- 为共享 ptr 向量实现复制 c'tor?
- 字符和整数中 **(ptr+1) 的值差异
- C++:在不中断共享的情况下通过引用传递共享 PTR?
- 如何将派生类从基 ptr 分配给 nlohmann::json
- 引用 std::shared:ptr 以避免引用计数
- 为什么我不能在不进行任何转换的情况下将浮点数放入任何类型的 ptr 中?
- 在调用函数时,ptr** 和 ptr*& 之间是否有区别,或者首选C++?
- 另一种类型的智能ptr,比如具有弱refs的unique_ptr
- 尝试打印出 *ptr++ 的值,以了解它是如何工作的
- 如何控制共享 ptr 引用计数?
- dopen():不以 root 身份运行时"failed to map segment from shared object"
- C++中的指针否定 (!ptr == NULL)
- 从const ptr*转换为ptr*时出现问题
- 无法使用 libtool 将 -shared 参数传递给 g++
- boost::shared_ptr和std::shared-ptr的同居
- 我可以用std::shared_ptr而不是boost::shared-ptr构建boost库吗
- shared-ptr-C++shared_ptr与unique_ptr用于资源管理