Hi, i have a question, so suppose you have a function and it had a return value that was a reference like int& foo(), why would you return an int instead of a int& like the return value says we're suppose to return??
Printable View
Hi, i have a question, so suppose you have a function and it had a return value that was a reference like int& foo(), why would you return an int instead of a int& like the return value says we're suppose to return??
You say it right in your title -- you are returning an int by reference, not returning a reference-to-int. (EDIT: To say it perhaps a different way, there's not really a different "type" involved -- an int& can't exist in isolation, it must be a reference to an actually-existing int.)