Answer to the last few comments.
I will give you an example of const applied to pointers with ints,
int a = 2; int b = 3; int* p1 = &a; // Modifiable pointer modifiable value const int* p2 = &a; // Modifiable pointer const value int* const p3 = &a; // Const pointer modifiable value const int * const p4 = &a; // Const pointer const value *p1 = 3; // Ok, modifiable left-value *p2 = 4; // Error: non-modifiable left-value *p3 = 5; // Ok *p4 = 6; // Error p1 = &b; // Ok: modifiable pointer p2 = &b; // Ok p3 = &b; // Error p4 = &b; // Error
In your case, you are looking for a mutable pointer, but a const value. So you want a second case,
const MyClass1* ptr;
(This is what you originally had)
It would seem that you were not really trying to change the pointer?
source share