c++ - 使用 std::min "no matching function for call to ‘min(<brace-enclosed initializer list>)’ 时出错“

标签 c++ c++11 std min

正在关注 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 suggested:

为了使用 template <class T> T min (initializer_list<T> il),需要像 here 中提到的那样包含 <algorithm>

关于c++ - 使用 std::min "no matching function for call to ‘min(<brace-enclosed initializer list>)’ 时出错“,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44561919/

相关文章:

c++ - 从多个临时文件中创建引用

c++ - 无法在 map 的 map 的 STL map 中插入数据

c++ - 分离线程访问全局或静态对象

c++ - 如何将提取运算符 (>>) 与 vector<bool> 一起使用?

c++ - char指针的模板特化?

c++ - 显式复制构造函数和 std::sort

c++ - 如何创建没有类型名称的迭代器?

c++ - Ncurses 输出函数只接受常量数据

使用字符串作为打开文件路径的 C++ ifstream 错误。

c++ - 整数的双射映射