)’ 时出错“-6ren"> )’ 时出错“-正在关注 https://stackoverflow.com/a/9424211/3368959我正在尝试比较三个数字: #include int main() { std::cout )’-6ren">
gpt4 book ai didi

c++ - 使用 std::min "no matching function for call to ‘min()’ 时出错“

转载 作者:搜寻专家 更新时间:2023-10-31 01:31:55 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com