一時オブジェクトは非 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++ コンパイラの互換性に影響する変更点