程序如下:
[code:1]
#include <iostream>
using namespace std;
int main() {
const int i = 10;
int &n = const_cast<int&>(i);
n = 100;
cout << "i address is " << &i << "\n"
<< "n address is " << &n << "\n";
cout << " i value is " << i << "\n"
<< "n value is " << n << endl;
}
[/code:1]
可以看出去常量后n对i的引用依然有效而且实际指向的地址一样