Source Address Http://onlywish.me
The reference is not as complex as a pointer, and does not copy space, and always prefers it.
then delve deeper into C + + reference issues don't know how the use of reference return values is a big risk Foundation: when an object is passed as a value. The copy constructor of the class is called, Common, function parameters. = number assignment. I carried out the following experiment: has a function defined as follows: A & func (); returns a reference to a class the original, which I have called. A = func (); I believe that's what most people call after an experiment, the copy constructor is called once actually returns a reference to the stack, and then the variable a duplicates the object inside the stack so, when the reference function is called later, To call A & a = func (); if you want to write a class package to someone else, try to avoid referencing the return, because the wrong call will lead to the heap memoryData is not released.
"C + +" C + + reference return value should be cautious