In C++98,
references-to-non-const
can bind to lvalues
references-to-const can
bind to lvalues
references-to-const
can bind to rvalues
In C++11, the following was added:
rvalue_references-to-non-const
can bind to rvalues
rvalue_references-to-const
can bind to rvalues
Here is an example:
int main()
{
int lvalue =
3;
int & xxxxxx_ref_to_non_const_bound_to_lvalue = lvalue;
int const & xxxxxx_ref_to_xxx_const_bound_to_lvalue = lvalue;
// int & xxxxxx_ref_to_non_const_bound_to_rvalue
= 3; // Compile Error
int const & xxxxxx_ref_to_xxx_const_bound_to_rvalue = 3;
// int && rvalue_ref_to_non_const_bound_to_lvalue = lvalue; // Compile Error
// int
const && rvalue_ref_to_xxx_const_bound_to_lvalue = lvalue; // Compile Error
int && rvalue_ref_to_non_const_bound_to_rvalue = 3;
int const && rvalue_ref_to_xxx_const_bound_to_rvalue = 3;
return 0;
}
No comments:
Post a Comment