0$房天下问答|C++问题2$https://m.fang.com/ask/ask_1405110.html$https://static.soufunimg.com/common_m/m_public/201511/images/asksharedefault.png
packc/pages/ask/detail/detail?askid=1405110
共1个回答
-
-
-
信息港之夜
丨Lv 4
1:你写的那个交换函数名字好像不能用,因为库里面有这个名字的函数,你相当于重载了,不过是不正确的重载,改个函数名:my_swap();2:你的交换函数在实际程序中没有任何意义,因为无法返回正确的交换后的结果,所以我把你的交换函数稍微改了下,答案如下:#include<iostream> using namespace std;template<typename T> void my_swap(T &x,T &y) { T z ; z=x ;x=y ;y=z ; } void main(){ int t1,t2; float f1,f2; t1=100; t2=200; f1=10.25; f2=5.75; my_swap(t1,t2); my_swap(f1,f2); cout<<"t1="<<t1<<"\tt2="<<t2<<endl; cout<<"f1="<<f1<<"\tf2="<<f2<<endl; return;}//结果:/*t1=200 t2=100f1=5.75 f2=10.25请按任意键继续. . .*/
免责声明:问答内容均来源于互联网用户,房天下对其内容不负责任,如有版权或其他问题可以联系房天下进行删除。

关注成功