I know that const reference prolongs the life of a temporary locally. Now I am asking myself if this propriety can be extended on a chain of temporary objects, that is, if I can safely define:
std::string const& foo = aBar.getTemporaryObject1().getTemporaryObject2();
My feeling is that, since the the first method aBar.getTemporaryObject1()
returns already a temporary object, the propriety doesn't hold for aBar.getTemporaryObject2()
.