#include<iostream> #include<algorithm> #include<string> using namespace std; void OverFlow(const int &max) { int &tmp=const_cast<int&>(max); tmp=200; cout<<"the value of tmp"<<tmp<<endl;//输出200 cout<<"max in the function"<<max<<endl;//输出200 } int main() { const int maxint=100; const int *ptr=&maxint; OverFlow(maxint); cout<<"max in the main"<<maxint<<endl;//值为100,说明编译器用100做了替换。 // 等效语句为 cout<<"max in the main"<<100<<endl; cout<<"the value of ptr"<<*ptr<<endl;//值为200,说明maxint的值被改变了 return 0; }