function parameter & return value (reference value efficiency is higher than value pass)
1) Consider using object references as much as possible, and use const for situations where the function does not change the content of the object.
2) Return value use object reference as much as possible, only return object cannot be a reference if the return value is a local object
The reason is that the local object will be refactored after the function has finished executing, and the external reference will correspond to an invalid object.
For a chestnut to understand the function of the argument, assuming that you have a file to be handled by others, you have to pass the file to others in a way that simply can have two kinds:
1, a copy of the document sent to each other, then let him deal with, such a benefit is that his changes will not affect your original file
The disadvantage is that space is wasted, which is equivalent to the way the function passes the parameter values.
2, tell the other side you want to deal with the location of the file, let him visit and deal with, such a benefit is to save space time,
The bad thing is that the other person will change to your original file, in order to deal with this situation, you can consider setting the appropriate permissions, such as read-only
This method is equivalent to the reference pass of the function parameter, and the setting of the permission is whether to add const
Second, operator overloading
Format: return value opreator operator (argument list) {function Body}
1) Note the parameter and return value of the function
2) for cases in which operators need to be used continuously, return a reference
Third, the use of const
1) Use a const reference for immutable object arguments
2) using the const identifier for member functions that do not modify member data is a good coding habit
C + + Learning Notes Object-oriented advanced programming @boolan