I saw the following description in one code:

const someclass *const *cls = ... 

In C ++ is not strong, I know enough about const . But what is this? Why and how to work with it? I did not understand what the two pointers seem to be indirect addressing, but I’m not sure.

I will be glad to advice and explanation))

Update: someclass - any class, at least empty. The meaning is not in it, if that :)

    2 answers 2

    This is a pointer to a pointer to an object of this class. The first const means that it is impossible to change the contents of the object itself with this pointer. The second const means that by means of this pointer it is impossible to change the contents of the pointer to which cls directly points.

    • It should be noted that in C ++ it does not seem to matter how to write access modifiers. Those. const typename const *xxx and const typename * const xxx are identical records. - gecube
    • Records const typename * XX and typename const * XX will be identical - you will get pointers to a typename constant. If you write const typename const * XX, you should get an error (g ++ does just that). - skegg

    Read from right to left: a pointer to a constant pointer to a constant of type someclass. This means that only the cls variable itself can be changed.