Why not non-const reference to temporary objects? [duplicate]
C++ allows assignment of temporary objects only to const reference. It wont allow assignement of temporary objects to reference. For example: String& a = String("test"); // Error const String& a = String("test"); // Ok Everywhere I google for this result, i only see the following answers Modifying temporary objects would cause unidentifiable problems Modifying temporary objects is dangerous At some point of time, you will forget it is a temporary variable It's been said, temporary objects vanishes after the statement. So you should not modify it. If C++, is so keen in blocking modifying the