编引用之swap()---高手帮忙写下笔记,还有解决一下问题,谢谢了

#include <iostream>
using namespace std;
void swap(int &x,int &y);
int main()
{
 int x=5,y=10;
 cout<<"main.before swap. x: "<<x<<" y: "<<y<<endl;
 swap(x,y);   //为什么和原型不一样哦????
 cout<<"main.after swap, x: "<<x<<" y: "<<y<<endl;
   return 0;
}
void swap(int &rx,int &ry)  //这里到底是什么意思??
{
 int temp;
 cout<<"swap.before swap. rx: "<<rx<<" ry: "<<ry<<endl;
 temp=rx;
 rx=ry;
 ry=temp;
 cout<<"swap.before swap. rx: "<<rx<<" ry: "<<ry<<endl;
}
posted @ 2008-12-03 16:36  雨城  阅读(294)  评论(0编辑  收藏  举报