0

请向我解释为什么我不能通过使用 next 来改变常量?

const int i = 10;
int * p = reinterpret_cast<int *>(&i);
4

2 回答 2

1

您应该使用const_castto cast away constness,const_cast专门针对这种情况。

于 2012-02-14T19:20:49.300 回答
0

const 表示恒定,因为您无法更改它。你可以做一个int nonconst_i = const_cast<int>(i);然后使用 nonconst_i

于 2012-02-14T19:21:24.323 回答