In C++,
function() = 10;
Works if function returns a variable by reference, right?
Would someone please elaborate on this in detail?
c++
In C++,
function() = 10;
Works if function returns a variable by reference, right?
Would someone please elaborate on this in detail?
Best Solution
Consider this piece of code first
Looks similar, isn't it? In this example,
function
returns a pointer toint
, and you can use it in the above way by applying a unary*
operator to it.Now, in this particular context you can think of references as "pointers in disguise". I.e. reference is a "pointer", except that you don't need to apply the
*
operator to itIn general, it is not a very good idea to equate references to pointers, but for this particular explanation it works very well.