When to use references vs. pointers

前端 未结 17 2625
一向
一向 2020-11-22 02:27

I understand the syntax and general semantics of pointers versus references, but how should I decide when it is more-or-less appropriate to use references or pointers in an

17条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 03:28

    In my practice I personally settled down with one simple rule - Use references for primitives and values that are copyable/movable and pointers for objects with long life cycle.

    For Node example I would definitely use

    AddChild(Node* pNode);
    

提交回复
热议问题