c++ - PointList &L 与 PointList L 的区别?
黄舟
黄舟 2017-04-17 12:58:06
0
2
739

最近看老师的程序
PointList 就是一个点列表结构体

struct Point
{
    float x, y;
};

struct PointList
{
    int size;
    int cur;
    struct Point points[10];
};

为什么有时候在函数中使用 PointList L 做参数,有时候使用 PointList &L,两者有什么区别呢?

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(2)
阿神

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.

阿神

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template