The original case for not allowing references to temporaries was for function parameters. Suppose this was allowed:
void inc(double& x)
{ x += 0.1; }
int i = 0;
inc(i);
Why isn’t i
changed?
More Related Contents:
- Non-const reference bound to temporary, Visual Studio bug?
- Temporary objects – when are they created, how do you recognise them in code?
- Where are temporary object stored?
- const reference to a temporary object becomes broken after function scope (life time)
- divide a number by 2 recursively
- C++ crash on getting pointer [closed]
- Difference between angle bracket < > and double quotes ” ” while including header files in C++? [duplicate]
- Check if element found in array c++
- What is a simple example of floating point/rounding error?
- How to read a CMake Variable in C++ source code
- How to parse a date string into a c++11 std::chrono time_point or similar?
- using namespace std; in a header file
- How to define a C++ preprocessor macro through the command line with CMake?
- Why/when is __declspec( dllimport ) not needed?
- How can I reliably get an object’s address when operator& is overloaded?
- SetupDiGetDeviceProperty usage example
- Precompiled headers with GCC
- What is the difference between MinGW, MinGW-w64 and MinGW-builds?
- C++ How is release-and-acquire achieved on x86 only using MOV?
- Should I copy an std::function or can I always take a reference to it?
- What is an iterator in general?
- Assembly ADC (Add with carry) to C++
- Returning a reference to a local variable in C++
- C++ error: ‘_mm_sin_ps’ was not declared in this scope
- Is Python faster and lighter than C++? [closed]
- if / else at compile time in C++?
- getchar_unlocked( ) VS scanf() VS cin
- DoEvents equivalent for C++?
- What information does GCC Profile Guided Optimization (PGO) collect and which optimizations use it?
- get part of std::tuple