2013-09-21 39 views
0

我打電話查找分鐘出兩個值 的代碼是一個模板:調用一個重載函數,而調用模板

#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功能不明確

+0

你知道存在std :: min嗎? – billz

+0

更具體地說,'template < class T > const T&std :: min(const T&a,const T&b)'。 – iavr

回答

1

刪除

using namespace std; 

因爲在STD另一個分鐘()函數。

0

使用::min(d,y)表示您引用全局名稱空間中的函數。