小编EGO*_*rds的帖子

函数不是std的元素

我在gcc下编译代码时遇到了一些奇怪的错误.它告诉我std::function不存在.

我可以使用以下代码重新创建错误:

#include <functional>
#include <stdio.h>

void test(){ printf ("test"); }

int main() {
    std::function<void()> f;
    f = test;
    f();
}
Run Code Online (Sandbox Code Playgroud)

如果我运行gcc(来自cygwin):(我的错误信息是德语,所以我翻译了它.在英语gcc上可能听起来不同)

$ gcc test.cpp
test.cpp: in function "int main(): 
test.cpp:7:3: Error: "function" is not an element of "std"« 
test.cpp:7:25: Error: "f" was not defined in this scope
Run Code Online (Sandbox Code Playgroud)

使用MSVC,它编译成功.请告诉我在我的代码中我做错了什么.

约翰内斯

c++

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×1