最近看老师的程序
PointList 就是一个点列表结构体
struct Point
{
float x, y;
};
struct PointList
{
int size;
int cur;
struct Point points[10];
};
为什么有时候在函数中使用 PointList L 做参数,有时候使用 PointList &L,两者有什么区别呢?
阿神2017-04-17 13:00:06
This is not C but C++, PointList &L
, I am used to writing it as PointList& L
, which declares a reference type. If the function parameter is not a reference type, a copy will be made. If it is a reference type, the original structure value will be passed.
阿神2017-04-17 13:00:06
In short, PointList L
passes the value and PointList &L
passes the address.
For non-primitive types, please always use PointList &L
as formal parameters. If you do not want to change the actual parameters, please use const PointList &L
.