While studying the copy substitution operator
Both of the chords above work I'm curious about the difference between Test&operator= and Testoperator=c++
If the return value of a function is in the form of a generic datatype (
Test), it returns the value by creating a new, unnamed temporary variable on the side that called the function before returning the return value.
On the other hand, when the return value is in reference format (
Test&), it returns the variable specified after the return that was accessible inside the function to the location where the function was called in reference format without creating a new temporary variable. Care must be taken to avoid returning the local variable of the function.
The question asked about Test and Test& in the return format, but this is not special, for example, if the return format is int and int&.
© 2022 pinfo. All rights reserved.