Const and const_cast of C ++
Today, I visited the Q & A community,
In C ++, someone asked about const_cast,
Exactly in < >.
I flipped through the books and searched the internet,
I found it quite interesting ....
The subject asks how to remove a const array of the double type set to const during running and then change the array content.
> First, make it clear that,
For const_cast
This is just a const for pointers and references. For variables, problems may occur.
For example, read the following code:
Const int a = 789; int & B = const_cast
(A); int * c = const_cast
(& A); cout <run:
Nice to play ~.~
> Then, for this question,
The array belongs to the pointer category because it is an array,
I tried to write,
Found,
Through an intermediate variable, you can change the content of the original const:
Const double arr [3] = {1.2, 3.3, 4.5}; int I; for (I = 0; I <3; ++ I) cout <(arr [0]); for (I = 0; I <3; ++ I) cout <The result is OK.
OK, that's it,
Interesting stuff ~.~