【发布时间】:2015-04-10 19:49:47
【问题描述】:
我正在尝试编译从网上获得的程序。尝试在代码块中使用,但显示错误。我不明白出了什么问题。我在各种论坛上查找过,但没有太多亮点。有人能尽快帮忙吗?提前致谢
#include <functional>
#include <iostream>
int print_num(int i, int j) { return i + j; }
int main() {
std::function<int(int, int)> foo = print_num;
std::function<int(int, int)> bar;
try {
std::cout << foo(10, 20) << '\n';
std::cout << bar(10, 20) << '\n';
} catch (std::bad_function_call& e) {
std::cout << "ERROR: Bad function call\n";
}
return 0;
}
这些是除了 14 个其他错误声明未完成之外的一些错误。我想清除这些错误可以解决这个问题。
main.cpp|10|错误:'function'不是'std'的成员
main.cpp|10|错误:表达式列表被视为函数转换中的复合表达式 [-fpermissive]
main.cpp|10|error: 在 'int' 之前的预期主表达式
【问题讨论】:
-
你是用 C++11 编译的吗?
-
始终包含顶部的错误。早期错误经常描述后来错误发生的原因。包括您的编译器是什么,以及您使用的编译器标志。