Gob*_*0st 9 c++ reference visual-studio-2010 rvalue lvalue
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();
}
Run Code Online (Sandbox Code Playgroud)
std::string&从类型的临时类型无效初始化类型的非const引用std::stringstd::string到std::string &非const引用可以仅被绑定到一个左值&&,而是在演示代码中,我只是使用非const左值引用!可以用somone帮我解释一下VS2010的行为吗?这是一个错误!?谢谢
Dav*_*eas 12
这是VS编译器的已知问题/特性.他们总是允许这样做,并且似乎没有任何推动去除该扩展.
编译器将在启用"禁用语言扩展"时发出错误,并在/ W4处发出警告.但是,删除此代码将破坏以前编译的代码,Microsoft非常不愿意这样做.这也是他们无法修复SFINAE支持的原因.
| 归档时间: |
|
| 查看次数: |
2892 次 |
| 最近记录: |