【发布时间】:2015-06-30 01:19:45
【问题描述】:
为什么我在执行这个程序时会出错? 我在这里找不到任何问题。
#include <iostream>
using namespace std;
void exchange(point& p);
int main()
{
struct point
{
int a, b;
};
point one = {1,2};
exchange(one);
cout << one.a << " , " << one.b;
return 0;
}
void exchange(point& p)
{
int temp;
p.a = temp;
p.a = p.b;
p.b = temp;
}
我在另一个程序中也遇到错误,它以类似的方式实现结构。
【问题讨论】:
-
你得到什么错误?
标签: c++ struct pass-by-reference