<<< | Index | >>> |
References can be returned by functions.
Why? To avoid copying overhead.
Generally used to return one of function arguments.
DON'T return references to locals !
int& counter() { static int count = 0; ++count; return count; // OK, count is static } int& disaster() { int count = calculate(); return count; // Oh, no!.. }
<<< | Index | >>> |