其他分享
首页 > 其他分享> > 001:简单的swap

001:简单的swap

作者:互联网

 1 #include <iostream>
 2 using namespace std;
 3 class A
 4 {
 5     public:
 6     int x;
 7     int getX() { return x; }    
 8 };
 9 void swap(
10 A& a,A& b
11 )
12 {
13     int  tmp = a.x;
14     a.x = b.x;
15     b.x = tmp;
16 }
17 int main()
18 {
19     A a,b;
20     a.x = 3;
21     b.x = 5;
22     swap(a,b);
23     cout << a.getX() << "," << b.getX();
24     return 0;
25 }

 

标签:tmp,20,cout,int,getX,001,swap,简单
来源: https://www.cnblogs.com/balabalabubalabala/p/16691150.html