在这种情况下,“绑定”意味着将引用绑定到特定对象。
int a;
int &b = a; // the reference is 'bound' to the object 'a'
void foo(int &c);
foo(a); // the reference parameter is bound to the object 'a'
// for this particular execution of foo.
http://coliru.stacked-crooked.com/a/5e081b59b5e76e03 http://coliru.stacked-crooked.com/a/5e081b59b5e76e03
然后阅读引用:
请注意不对称性:虽然 const 左值引用可以绑定到右值,
void foo(int const &);
foo(1); // the const lvalue reference parameter is bound to
// the rvalue resulting from the expression '1'
http://coliru.stacked-crooked.com/a/12722f2b38c74c75 http://coliru.stacked-crooked.com/a/12722f2b38c74c75
const 右值引用无法绑定到左值。
void foo(int const &&);
int a;
foo(a); // error, the expression 'a' is an lvalue; rvalue
//references cannot bind to lvalues
http://coliru.stacked-crooked.com/a/ccadc5307135c8e8 http://coliru.stacked-crooked.com/a/ccadc5307135c8e8
特别是,这使得 const 左值引用能够执行 const 右值引用可以执行的所有操作,甚至更多(即绑定到左值)。
void foo(int const &);
foo(1); // const lvalue reference can bind to rvalue
int a;
foo(a); // and lvalue
http://coliru.stacked-crooked.com/a/d5553c99e182c89b http://coliru.stacked-crooked.com/a/d5553c99e182c89b