0

I am using the library <functional> which defines the class function. But when I try to compile the code I get an error that function does not name a type.

Till recently I was using Microsoft Visual Studio and there was no problem. Now I sometimes work on Ubuntu 14.04 with Eclipse and g++ and got this error when compiling the same code (except the 'main').

I found here some similar problems but none of the solution works for me.

#include <functional>
using namespace std;

typedef function<double(double, double*)> t_function;

error on third line, I also tried different (and no namespaces) with different using and none works

Michal
  • 671
  • 3
  • 9
  • 22

1 Answers1

3

You either have an old version of gcc (less likely), or not compiling in c++11 mode (more likely), which is enabled with a compiler flag:

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 describes the process of enabling c++11 in Eclipse in-detail, though it is rather old.

Community
  • 1
  • 1
SingerOfTheFall
  • 29,228
  • 8
  • 68
  • 105