Open
Description
in cppguide.html,
Could somebody please elaborate 'use a const pointer when the non-optional form would have used a reference'? It will be also helpful if some examples can be added.
My understanding is as follows,
- Non-optional input parameters - values or const references
- Non-optional output and input/output parameters - references
- Optional input parameters(by value) - absl::optional
- the non-optional form would have used a reference(<= This means Optional input parameters by references?) - a const pointer
- Optional outputs and optional input/output parameters - non-const pointers
Thanks in advance.
Parameters are either inputs to the function, outputs from the function, or both. Non-optional input parameters should usually be values or const references, while non-optional output and input/output parameters should usually be references (which cannot be null). Generally, use absl::optional to represent optional by-value inputs, and use a const pointer when the non-optional form would have used a reference. Use non-const pointers to represent optional outputs and optional input/output parameters.