(std::string)"a" just tells the compiler: "Just suppose that "a" points to std::string "
No, this is not what distinguishes the type of object in general. Casting to an object type is an explicit conversion request. (std::string)"a" means "build a temporary std::string from a literal ( const char[] ) "a" .
In the declaration std::string s = (std::string)"a" + "b" + "c"; this temporary resource is stored until the initialization of s completed. (12.2 [class.temporary] / 4)
There are (at least) two subsequent timelines, the result of applying operator+ to the first temporary and "b" and the result of applying operator+ to this temporary and "c2" . This last temporary value is used for copy-initialize s . Upon completion of initialization, all temporary files are destroyed in the reverse order of their construction.
Initialization is valid and has the correct behavior.
source share