2013-05-06 60 views
3

我想玩弄C++ 11的新功能,即使用Smart Pointers。我发现了一个exampleg ++(Ubuntu的/ Linaro的4.7.2-2ubuntu1)4.7.2这里:Cplusplus11-Smart-Pointers激活智能指针?

#include <memory> 

int main() { 
    std::shared_ptr<int> sptr1(new int); 
} 

当我尝试一下就是一切,我得到:

In function ‘int main()’:| 
error: ‘shared_ptr’ was not declared in this scope| 
error: expected primary-expression before ‘int’| 
error: expected ‘;’ before ‘int’| 

这是我的G ++版本:

g++ (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2 

我必须首先“激活”C++ 11吗?

+5

您需要使用'-std = C++ 11'编译器标志。 – juanchopanza 2013-05-06 18:25:12

+0

我可以在哪里输入该标志?我使用Code :: Blocks 10.05。 – user1170330 2013-05-06 18:29:56

+0

设置>编译器>编译器设置>其他选项 – Morwenn 2013-05-06 18:39:35

回答

3

您需要将-std=c++11编译器标志传递给G ++编译器。代码块允许您通过

设置配置此 - >编译器 - >编译器设置

注意旧版本的GCC,你可能需要-std=c++0x