g ++是否包含功能库?

时间:2016-05-10 14:16:15

标签: g++

我在g ++中使用功能时遇到问题。我使用!g++ -o test test.cpp -std=c++11编译它并没有给出任何错误,程序也运行良好。我在编译之前使用Syntastic来检查任何错误,它给了我以下输出。

这是我的程序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 }

错误是:

  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’

这个错误是什么意思,我该如何解决?

1 个答案:

答案 0 :(得分:0)

问题是Syntastic没有检查c ++ 11代码,因为函数只能用于c ++ 11。这就是编译运行正常并且输出文件显示正确结果的原因。

在发现问题的根源后,我在这个问题中找到了答案:

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

所以我只需要添加

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

到我的vimrc

相关问题