gpt4 book ai didi

c++ - 调用模板时调用重载函数

转载 作者:行者123 更新时间:2023-11-28 03:09:16 25 4
gpt4 key购买 nike

我正在调用一个模板来从两个值中找出最小值代码是:

#include<iostream>
#include <cstdlib>

using namespace std;

template<class T>
T min(T a,T b)
{
return (a<b)?a:b;
}


int main(int argc, char** argv) {
int d,y;
std::cout<<"enter two integer values";
std::cin>>d>>y;
cout<<"you entered"<<d<<y;
std::cout<<"the minimum of the two is "<<min(d,y);
float p,q;
std::cout<<"enter float values";
std::cin>>p>>q;
cout<<"you entered"<<p<<q;
std::cout<<"the minimum of the float values is "<<min(p,q);
char w,a;
std::cout<<"enter the two characters";
std::cin>>w>>a;
cout<<"you entered"<<w<<a;
std::cout<<"the minimum of the two characters is "<<min(w,a);
return 0;

它说对 ovrloaded 函数的调用不明确

最佳答案

删除

using namespace std;

因为std中还有一个min()函数。

关于c++ - 调用模板时调用重载函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18932018/

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