You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
The text was updated successfully, but these errors were encountered:
It's trying to clarify the comparisons: T* is to T& what optional<T> is to T. If you would be passing by value, but want optionality, you pass optional<T>. If you would be passing by reference but want optionality, pass T*.
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,
Thanks in advance.
The text was updated successfully, but these errors were encountered: