Can anyone tell me why visual studio c++ compiler does not allow me to do that:
string& s = "abc";
but I can do that:
string& s = string("abc");
When I tried to compile the second example on linux, the g++ compiler actually threw an error, which is what I would expect. Quick google search told me that in the second case, the lifespan of temporary variable is extended to the lifespan of the reference, but then again, what is wrong with the first example and why g++ complains about it?