Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Visual C++
Reference
C/C++ Languages
 Temporary Objects Cannot be Bound t...
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
Visual C++ Language Reference
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 &
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker