关于函数模板和应用,这个程序错在哪里??
#include<iostream>template<typenameany>voidswap(any&a,any&b);intmain(){usingnamespace...
#include<iostream>
template<typename any>
void swap(any & a,any & b);
int main()
{
using namespace std;
int i=10, j=20;
cout<<"i="<<i<<endl<<"j="<<j<<endl;
swap(i,j);
cout<<"now "<<"i="<<i<<endl<<"j="<<j<<endl;
double x=12.32,y=45.36;
cout<<"x="<<x<<endl<<"y="<<y<<endl;
swap(x,y);
cout<<"now "<<"x="<<x<<endl<<"y="<<y<<endl;
return 0;
}
template<class any>
void swap(any & a,any & b)
{
any tem;
tem=a;a=b;
b=tem;
} 展开
template<typename any>
void swap(any & a,any & b);
int main()
{
using namespace std;
int i=10, j=20;
cout<<"i="<<i<<endl<<"j="<<j<<endl;
swap(i,j);
cout<<"now "<<"i="<<i<<endl<<"j="<<j<<endl;
double x=12.32,y=45.36;
cout<<"x="<<x<<endl<<"y="<<y<<endl;
swap(x,y);
cout<<"now "<<"x="<<x<<endl<<"y="<<y<<endl;
return 0;
}
template<class any>
void swap(any & a,any & b)
{
any tem;
tem=a;a=b;
b=tem;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询