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?

4

1 回答 1

3

您需要将-std=c++11编译器标志传递给 g++ 编译器。CodeBlocks 允许您通过以下方式进行配置

设置 -> 编译器 -> 编译器设置

请注意,对于旧版本的 gcc,您可能需要-std=c++0x.

于 2013-05-06T18:42:48.643 回答