2012-11-18 56 views
13

我似乎在这里失去了一些东西。我从boost::shared_ptr移到std::shared_ptrshared_ptr是TR1的一部分,早在2000年代中期,它应该是随处可见在2012年苹果和shared_ptr

尝试使用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中(完全修补),和命令行工具。

那么如何在Apple平台上使用std :: shared_ptr?

+0

'苹果'似乎不是一个好标签 –

+0

什么工具链版本?这是真正重要的。坦率地说,我不在乎你的操作系统! –

+0

感谢Lightness。了解。我也不太关心苹果。 – jww

回答

20

#include <tr1/memory>可以与使用libstdC++的编译器一起使用。或者,与Clang:

#include <memory> 
using std::shared_ptr; 

并编译c++ -std=c++11 -stdlib=libc++ ...。我不知道为什么Clang默认使用libstdC++;大概是为了兼容GCC。

由于libstdC++没有手册页,因此无法找到手册页。有帮助,不是吗。源代码发布中有HTML文档。

+0

完美,谢谢。 – jww

+0

“有帮助,是不是” - 这是否意味着我们是老? – jww