主题:各位,麻烦帮忙看下这个程序啦!程序里的函数模板为甚么调用不了呢?
#include<iostream>
using namespace std;
template<class T>
void swap( T x1, T x2 )
{
T x;
x = x1;
x1 = x2;
x2 = x;
}
void swap( int x1, int x2 )
{
int x;
x = x1;
x1 = x2;
x2 = x;
return ;
}
int main()
{
char c1 = 'a', c2 = 'y';
swap( c1, c2 ); //调用生成的char型模板函数
int t1 = 8, t2 = 7;
swap( t1, t2 );
char y1 = 'f';
double y2 = 5.6;
swap( y1, y2 );
return 0;
}
using namespace std;
template<class T>
void swap( T x1, T x2 )
{
T x;
x = x1;
x1 = x2;
x2 = x;
}
void swap( int x1, int x2 )
{
int x;
x = x1;
x1 = x2;
x2 = x;
return ;
}
int main()
{
char c1 = 'a', c2 = 'y';
swap( c1, c2 ); //调用生成的char型模板函数
int t1 = 8, t2 = 7;
swap( t1, t2 );
char y1 = 'f';
double y2 = 5.6;
swap( y1, y2 );
return 0;
}