【发布时间】:2016-01-27 06:39:41
【问题描述】:
考虑以下代码 sn-p。
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**
它给出编译错误转换丢失限定符。
请提出一个替代方案来实现它。
【问题讨论】:
-
正如您从链接的欺骗中看到的那样,这具有潜在的风险,并且在任何情况下您可能都想考虑摆脱多重间接,在 C++ 中通常有更好的处理方法。
-
现在允许这样做的原因在Question 11.10 of the C FAQ 中进行了解释。不要这样做。
标签: c++ casting compiler-errors int type-conversion