【发布时间】:2013-09-21 11:27:20
【问题描述】:
我正在调用一个模板来从两个值中找出一个最小值 代码是:
#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;
}
它说对重载函数的调用不明确
【问题讨论】:
-
你知道有std::min吗?
-
更具体地说,
template< class T > const T& std::min( const T& a, const T& b )。