表达式列表被视为复合表达式
Expression list treated as compound expression
我正在尝试编译一个从网上得到的程序。尝试在代码块中使用,但它显示错误。我不明白出了什么问题。我在各种论坛上查找过,但没有太多的线索。谁能帮忙很快?提前致谢
#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 calln";
}
return 0;
}
这些是除 14 个其他错误之外的一些错误,表示声明未完成。我想清除这些错误可以解决这个问题.
main.cpp|10|error:"function"不是"std"
的成员 main.cpp|10|错误:表达式列表在函数强制转换中被视为复合表达式 [-允许]
main.cpp|10|error:在"int"之前预期的主表达式
您需要
使用-std=c++11
进行编译才能添加C++11功能。
$ g++ -std=c++11 test.cxx && ./a.out
30
ERROR: Bad function call
与:
$ g++ test.cxx && ./a.out
test.cxx: In function ‘int main()’:
test.cxx:10:3: error: ‘function’ is not a member of ‘std’
test.cxx:10:28: error: expression list treated as compound expression in functional cast [-fpermissive]
test.cxx:10:17: error: expected primary-expression before ‘int’
...
相关文章:
- (C++)分析树以计算返回错误值的简单算术表达式
- 在VS2010-VS2015下编译时,如何使用decltype作为较大类型表达式的LHS
- 提升精神:解析布尔表达式并简化为规范范式
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 使用正则表达式regex_search在字符串中查找字符串
- 如何确认我的constexpr表达式实际上已经在编译时执行
- 概念中的cv限定符需要表达式参数列表
- 为什么constexpr的性能比正常表达式差
- C++模板函数中的初始化 - 新的初始值设定项表达式列表被视为复合表达式
- 为什么这个复合语句作为用大括号和括号括起来的语句序列似乎不是有效的语句表达式
- 复合赋值的左侧表达式是未初始化的值.计算出的值也将是垃圾
- if 语句中的复合表达式
- C 套接字误差(新的初始器表达式列表被视为复合表达式)
- 错误:表达式列表在初始化器[-fpermissive] Double Paycalc(p,yir,y)中被视为复合表达式
- 可变模板:表达式列表在函数转换错误中被视为复合表达式
- 表达式列表被视为复合表达式
- 将提升 lambda 与复合表达式结合使用
- 表达式列表在初始化器中被视为复合表达式
- 表达式列表在创建指向 Mat 向量的指针时被视为初始值设定项中的复合表达式
- 函数强制转换中作为复合表达式处理的表达式列表[-fpermissive]