class AA {
private:
string s = "asd";
public:
string func1() {
return s;
}
string& func2() {
return s;
}
};
func1()
returns a copy and func2()
returns a reference.
And calls are like
AA a;
auto &r1 = a.func1();
auto &r2 = a.func2();
Both work fine after I test them.
But here is my doubt.
r2
refers to AA::s
; I get it. But does r1
refer to AA::s
too? Or func1
's anonymous return value?
If the former, how does func1
do it? RVO?