Spa*_*rsh 0 c++ struct pass-by-reference
为什么我在实施这个程序时遇到错误?我在这里找不到任何错误.
#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;
}
Run Code Online (Sandbox Code Playgroud)
我也在另一个程序中遇到错误,它以类似的方式实现Structures.