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
Why I can't have a const reference that references to a non-const pointer? I thought that if you access the const ptrRef
identifier, it will treat val2
as const. When you access ptr
, it will treat val2
as non-const. This works for the bottom part of the code, so I don't understand why it won't work for pointers.