C / C ++类型转换将int **转换为const int **

时间:2016-01-27 06:39:41

标签: c++ casting compiler-errors int type-conversion

请考虑以下代码段。

int** ptr;  // memory pointed by ptr is initialized to its content.
const int** ptrConst;
ptrConst = ptr // Now I want to convert it type of const int**

它使编译错误转换失去限定符。

请建议另一种方法来实现它。

1 个答案:

答案 0 :(得分:0)

您可以使用const_cast

ptrConst = const_cast<const int**>(ptr);

您可能希望阅读this问题,了解为什么这不是一个好主意。