const std::string& f(){
std::string s = "Hello";
return s + s;
}
int main() {
std::string s = "Hello";
std::string& s1 = s + s;
s1 += "!";
std::cout << f();
}
私が書いたこのコードについていくつか質問があります。
一時オブジェクトへの非 const 参照であっても、s1 にアクセスして変更できるのはなぜですか?
f で実行時エラーが発生するのはなぜですか? const は一時オブジェクトの寿命を延ばすと思いましたか?