Note that your code would compile only with C++11 compiler.
When you pass an integral literal, which is by default of int
type, unless you write 1L
, a temporary object of type int
is created which is bound to the parameter of the function. It's like the first from the following initializations:
int && x = 1; //ok. valid in C++11 only.
int & y = 1; //error, both in C++03, and C++11
const int & z = 1; //ok, both in C++03, and C++11
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…