64,646
社区成员
发帖
与我相关
我的任务
分享
template < class T >
int compare( T a,T b )
{
if( a < b )
return 1;
else if( b < a )
return -1;
else
return 0;
}
int main(int argc,char *argv[] )
{
int a[3]={1,2,3};
int b[3] = {4,5,6};
double a1[3]={1,2,3};
double b1[3] = {4,5,6};
cout << compare( a, b);
cout << compare( a1,b1);
return EXIT_SUCCESS;
}
#include<iostream>
#include<sstream>
using namespace std;
template<class T>
T getValue(string s) { //模板参数用作返回值,无法推导
T value;
istringstream is(s);
is >> value;
return value;
}
int main(int argc, char* argv[])
{
double a = getValue<double>("10.12"); //自己提供
return EXIT_SUCCESS;
}