使用std :: min时出错,“没有匹配的函数调用"min(<括号括起来的初始化程序列表>)"" [英] Error when using std::min "no matching function for call to ‘min(<brace-enclosed initializer list>)’"
本文介绍了使用std :: min时出错,“没有匹配的函数调用"min(<括号括起来的初始化程序列表>)""的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 https://stackoverflow.com/a/9424211/3368959 之后,我尝试比较三个数字:
Following https://stackoverflow.com/a/9424211/3368959 I am trying to compare three numbers:
#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>)’
但是,代码在使用时可以正常编译
However, the code compiles just fine when using
std::min(std::min(2,5),1)
但是第一种方法应该与c ++ 11标准一起使用.我可能做错了什么?
But the first way should work with the c++11 standard. What could I be doing wrong?
推荐答案
As @BoBTFish suggested:
要使用template <class T> T min (initializer_list<T> il)
,需要包含<algorithm>
,如所述此处.
In order to use template <class T> T min (initializer_list<T> il)
one needs to include <algorithm>
as is mentioned here.
这篇关于使用std :: min时出错,“没有匹配的函数调用"min(<括号括起来的初始化程序列表>)""的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文