int * const cpi_1 = &i; //cpi_1是一个指向const int 类型,被定义为非const对象的指针 *cpi_1 = 10; // cpi = cpi + 1;
return 0; } //End of main
#include <iostream> using std::cout; using std::endl;
int main() { int ival = 0; const int ival3 = 1; const int &rval1 = 1.01; int &rval2 = ival; int * const &rval3 = &ival; int *pi = &ival; int * &rval4 = pi; int &rval5 = *pi;
//int &* prval1 = pi;//error: cannot declare pointer to 'int&' int * & prval1 = pi;//right
const int & ival2 = 1;
//const int * & prval2 = &ival3;//error: cannot bind non-const lvalue reference of type 'const int*&' to an rvalue of type 'const int*' const int * const & prval2 = &ival3;
//int * & prval3 = &ival;//error: cannot bind non-const lvalue reference of type 'int*&' to an rvalue of type 'int*' const int * & prval3 = &ival;//error: cannot bind non-const lvalue reference of type 'int*&' to an rvalue of type 'int*' //const int * const & prval3 = &ival1; return 0; } //End of main