Guidelines for parameter passing

"C++ Programming Language 4th Edition" Chapter 12.2.1

1. Small objects are passed by value.

2. Large objects that do not need to be modified are passed by const reference.

3. If you need to return the calculation result, it is better to use return instead of modifying the object by passing parameters.

4. If the appropriate transfer method cannot be determined, the pointer transfer will be given priority.

5. Don't use non-const reference passing as a last resort. Passing a pointer when you want to modify the value of an object is easier to understand than passing a reference.

Guess you like

Origin blog.csdn.net/kenfan1647/article/details/114004914