为什么会出现此错误:“const int *”类型的值无法分配给“int *”类型的实体?

时间:2015-12-31 06:56:58

标签: visual-c++

这是我的代码:

int i = 5;
const int * cpi = &i; //pointer to const
int * pi = cpi; //Error: a value of type "const int*" cannot be assigned to an entity of type "int*"

1 个答案:

答案 0 :(得分:0)

i是可变的,因为它不是const类型。 您尝试通过cpi将int地址存储在const int地址中。

要解决这个问题,你必须实际交出价值而不是地址。

相关问题