问题
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;
}
But the compiler gives me the error:
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)
But the first way should work with the c++11 standard. What could I be doing wrong?
回答1:
As @BoBTFish suggested:
In order to use template <class T> T min (initializer_list<T> il)
one needs to include <algorithm>
as is mentioned here.
来源:https://stackoverflow.com/questions/44561919/error-when-using-stdmin-no-matching-function-for-call-to-minbrace-enclosed