更新:2007 年 11 月
在 Visual C++ 以前的版本中,可以将非常量引用绑定到临时对象。 现在,只能将临时对象绑定到常量引用。
示例
例如,与 Visual Studio .NET 相比,以下示例在 Visual Studio .NET 2003 中具有不同的运行时行为:
// bc_temp_objects_not_bound_to_nonconst_ref.cpp
// compile with: /EHsc
#include "iostream"
using namespace std;
class C {};
void f(C & c) { cout << "C&" << endl; }
void f(C const & c) { cout << "C const &" << endl; }
int main() {
f(C());
}
C const &