Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Temporary Objects Cannot be Bound to Non-Const References

In previous releases of Visual C++, non-const references could be bound to temporary objects. Now, temporary objects can only be bound to const references.

For example, the following sample compiles has different run-time behavior in Visual Studio .NET 2003 compared to 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());
}

Output

C const &

Community Additions

ADD
Show:
© 2015 Microsoft