6.11a References and const

原完整教程链接:6.11a References and const

1.
/*
   Unlike references to non-const values, which can only be initialized 
   with non-const l-values, references to const values can be initialized 
   with non-const l-value, const l-values, and r-values.
*/

int x = 5;
const int &ref1 = x; // okay, x is a non-const l-value
 
const int y = 7;
const int &ref2 = y; // okay, y is a const l-value
 
const int &ref3 = 6; // okay, 6 is an r-value

你可能感兴趣的:(6.11a References and const)