共用方式為


暫存物件無法繫結至非 Const 的參考

更新:2007 年 11 月

在之前的 Visual C++ 發行版本中,非 Const 的參考都能繫結至暫存物件。現在,暫存物件只能繫結至 Const 的參考。

範例

例如,在經過比較之後,下列範例在 Visual Studio .NET 2003 與 Visual Studio .NET 具有不同的執行階段行為:

// 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 &

請參閱

參考

Visual C++ 編譯器的重大變更