Take a look at the following example:
string foo(int i) { string a; ... Process i to build a ... return a; } void bar(int j) { const string& b = foo(j); cout << b; }
I know RVO and NRVO, but I thought that for this I need to write bar as follows:
void bar(int j) { string b = foo(j); cout << b; }
Both versions seem to work, and I believe that with the same performance. Is it possible to use the first version (with reference to a constant)?
Thanks.
source share