Why this Error: a value of type “const int*” cannot be assigned to an entity of type “int*”?

邮差的信 提交于 2021-02-19 15:26:38

问题


This is my code:

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:


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.



来源:https://stackoverflow.com/questions/34542470/why-this-error-a-value-of-type-const-int-cannot-be-assigned-to-an-entity-of

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!