使用 std::min "no matching function for call to ‘min(<brace-enclosed initializer list>)’"时出错
Error when using std::min "no matching function for call to ‘min(<brace-enclosed initializer list>)’"
按照 https://stackoverflow.com/a/9424211/3368959,我试图比较三个数字:
#include <iostream>
int main() {
std::cout << std::min({2,5,1}) << std::endl;
return 0;
}
但是编译器给了我错误:
error: no matching function for call to ‘min(<brace-enclosed initializer list>)’
但是,代码在使用时编译得很好
std::min(std::min(2,5),1)
但第一种方法应该与 c++11 标准一起使用。我可能做错了什么?
正如@BoBTFish所建议的:
为了使用template <class T> T min (initializer_list<T> il)
需要包括这里提到的<algorithm>
。
相关文章:
- 如何使用std::min和std::less返回对象
- 为什么 -mmacosx-version-min=10.10 不阻止使用标记为从 10.11 开始的函数?
- 关于 std::min, std::max 中的比较运算符的混淆
- 使用 CImg 库的 std::min 和 std::max 的编译问题
- 当初始值设定项是基类名时'initializer does not name a non-static data member or base class'错误
- 为什么将 1 添加到 numeric_limits<float>::min() 返回 1?
- C2664 无法从'initializer list'转换参数
- C++ 错误:"array must be initialized with a brace-enclosed initializer"
- 在儿童的特定情况下,向下渗透MIN二进制堆失败
- 在f2c.h文件中定义min()max()宏时出错
- 如何解决g++问题"internal compiler error: Illegal instruction min() _GLIBCXX_USE_NOEXCEPT { return __FLT_MI
- 第 5 行:字符 54:错误:调用"min(int,std::__cxx11::basic_string<char>::size_type)"没有匹配函数
- 如何使用函数std::min()来计算最小值
- 2D 数组中的"Excess elements in scalar initializer"错误
- 在函数 'int main(int, char**) 中,没有声明 'MIN'
- 将迭代器值与 std::min 一起固定到 end()
- C++是否在 std::min 和 std::max 下标准化 std::optional 的行为?
- c++ 中 std::min 的效率
- 当摆脱模偏差时,min = -upper_bound % upper_bound; // 如何工作?
- 使用 std::min "no matching function for call to ‘min(<brace-enclosed initializer list>)’"时出错