language: C++ 4.7.2 (gcc-4.7.2)
date: 124 days 6 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
 
// Invalid example:
void foo(int& x)
{
    std::cout << x << std::endl;
}
 
int main()
{
    // not legal; can't bind a temporary to a non-const reference (because what if foo() changed it?)
    foo(7 * 6);
}
prog.cpp: In function ‘int main()’:
prog.cpp:12: error: invalid initialization of non-const reference of type ‘int&’ from a temporary of type ‘int’
prog.cpp:4: error: in passing argument 1 of ‘void foo(int&)’