小编God*_*rew的帖子

将 const 指针引用绑定到非常量指针

int val2 = 38;
int *ptr = &val2;
const int *&ptrRef = ptr; // ERROR

int i = 92;
int &ref_i = i;
const int &ref_i2 = ref_i;  // OK
Run Code Online (Sandbox Code Playgroud)

为什么我不能有一个引用非常量指针的常量引用?我认为如果你访问 constptrRef标识符,它将被视为val2const。当您访问 时ptr,它将被视为val2非常量。这适用于代码的底部部分,所以我不明白为什么它不适用于指针。

c++ pointers reference

7
推荐指数
1
解决办法
412
查看次数

标签 统计

c++ ×1

pointers ×1

reference ×1