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