激活智能指针?

时间:2013-05-06 18:24:28

标签: c++ pointers c++11 smart-pointers

我想要使用C ++ 11的新功能,即使用Smart Pointers。我在这里找到了一个示例++(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?

1 个答案:

答案 0 :(得分:3)

您需要将-std=c++11编译器标志传递给g ++编译器。 CodeBlocks允许您通过

配置它
  

设置 - &gt;编译器 - &gt;编译器设置

对于旧版本的gcc,

注意,您可能需要-std=c++0x