To add / remove const , use const_cast .
To deal with confusing casting errors, do something one at a time:
int* var; int** v2 = &var; int const** v3 = const_cast<int const**>(v2); void const** v4 = reinterpret_cast<void const**>(v3);
Note that a int const** and a int** are very different types, and converting between them is dangerous - more dangerous than a void* β int* .
Suppose you have int** bob . Then you pass it to a function that takes int const** alice through const_cast .
In this function, they assign a pointer to an int stored in read-only memory, to *alice - completely legal.
Outside of the function, you check that bob and *bob valid, then assign **bob , and you just tried writing to read-only memory.
source share