Error when using std::min “no matching function for call to ‘min(<brace-enclosed initializer list>)’”

余生颓废 提交于 2019-12-24 04:02:49

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!