I was studying about const qualifier with the book C++ Primer by Stanley B. Lippman but when I read about top-level and low level consts I got confused in the part where it envolves pointers.
For example:
In this part of the code
const int ci = 42; //ok
const int *p2 = &ci; //ok
const int *const p3 = p2; //ok
int *p = p3; //error
p2 = p3; //ok
I understand that p3
has both, top-level and low-level const, because the object itself is const and the pointer can point to a const object.
I don't understand correctly why top-level consts are ignored and why I can assign p3
to p2
but I cannot use p3
to initialize p
. Can anyone explain me, with more details, the reason why it happens?
PS: I already saw What are top-level const qualifiers? question and it didn't help me that much.