string foo() { return "hello"; }
int main()
{
//below should be illegal for binding a non-const (lvalue) reference to a rvalue
string& tem = foo();
//below should be the correct one as only const reference can be bind to rvalue(most important const)
const string& constTem = foo();
}
std :: string &
из временный тип std :: string
std :: string
в std :: string &
неконстантный
ссылка может быть привязана только к lvalue &&
, вместо этого в демонстрационном коде я просто использовал неконстантную ссылку lvalue! Может кто-нибудь помочь мне объяснить здесь поведение VS2010? Это ошибка !? Спасибо