'function' 没有命名类型(在 Eclipse 中)
'function' does not name a type (in Eclipse)
我正在使用定义 class function
的库 <functional>
。但是当我尝试编译代码时,我得到一个错误,即 function
does not name a type.
直到最近我一直在使用 Microsoft Visual Studio 并且没有任何问题。现在,我有时会使用 Eclipse 和 g++ 在 Ubuntu 14.04 上工作,并在编译相同代码时遇到此错误('main' 除外)。
我在这里发现了一些类似的问题,但 none 的解决方案对我有用。
#include <functional>
using namespace std;
typedef function<double(double, double*)> t_function;
第三行出错,我也尝试了不同的(没有名称空间)和不同的使用 none 有效
您使用的是旧版本的 gcc(不太可能),或者未在 c++11 模式下编译(更有可能),这是通过编译器标志启用的:
C++11 features are available as part of "mainline" GCC in the trunk of GCC's repository and in GCC 4.3 and later. To enable C++0x support, add the command-line parameter -std=c++0x to your g++ command line. Or, to enable GNU extensions in addition to C++0x extensions, add -std=gnu++0x. GCC 4.7 and later support -std=c++11 and -std=gnu++11 as well.
This question详细介绍了在Eclipse中启用c++11的过程,虽然比较老
我正在使用定义 class function
的库 <functional>
。但是当我尝试编译代码时,我得到一个错误,即 function
does not name a type.
直到最近我一直在使用 Microsoft Visual Studio 并且没有任何问题。现在,我有时会使用 Eclipse 和 g++ 在 Ubuntu 14.04 上工作,并在编译相同代码时遇到此错误('main' 除外)。
我在这里发现了一些类似的问题,但 none 的解决方案对我有用。
#include <functional>
using namespace std;
typedef function<double(double, double*)> t_function;
第三行出错,我也尝试了不同的(没有名称空间)和不同的使用 none 有效
您使用的是旧版本的 gcc(不太可能),或者未在 c++11 模式下编译(更有可能),这是通过编译器标志启用的:
C++11 features are available as part of "mainline" GCC in the trunk of GCC's repository and in GCC 4.3 and later. To enable C++0x support, add the command-line parameter -std=c++0x to your g++ command line. Or, to enable GNU extensions in addition to C++0x extensions, add -std=gnu++0x. GCC 4.7 and later support -std=c++11 and -std=gnu++11 as well.
This question详细介绍了在Eclipse中启用c++11的过程,虽然比较老