0

I have problems with using functional in g++. I compile with !g++ -o test test.cpp -std=c++11 and it does not give any errors and the program also runs fine. I use Syntastic to check any errors before compiling, and it gives me the following output.

This is my program test.cpp:

    1 #include <functional>
    2 
    3 using namespace std;
    4 
    5 int f(int x){
    6         return x;
    7 }
    8         
    9 void f2(function<int(int)> f){
   10 
   11 }
   12 
   13 int main(){
   14         return 0;
   15 }

The error is:

  1 test.cpp|9 col 9 error| variable or field ‘f2’ declared void                                        
  2 test.cpp|9 col 9 error| ‘function’ was not declared in this scope
  3 test.cpp|9 col 18 error| expected primary-expression before ‘int’

What does this error mean and how do I fix it?

1 Answers1

0

The problem was that Syntastic was not checking c++11 code since functional can only be used with c++11. That was the reason the compiling went fine and the output file displayed correct results.

I found the answer in this question after discovering the root of the problem:

how to add c++11 support to syntastic vim plugin?

so I just had to add

let g:syntastic_cpp_compiler_options = ' -std=c++11 -stdlib=libc++'

to my vimrc

Community
  • 1
  • 1