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

问题描述:

这是我的代码:

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*"

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

i is mutable, cause it is not a const type. You try to store a int address in a const int address via cpi.

要解决它,您必须实际交出值而不是地址.

To solve it you have to actually hand over the values not the addresses.