I'm trying to make a non-constant array of non-constant pointers to constant objects. The idea is that I should be able to change what the pointers in the array point to, but what they point to is a constant object.
I'm having problem defining this array (it's an array of pointers to objects of type Person - a custom class). I'm currently declaring the array like so:
Person* people[10];
Also that's not explicitly saying that the pointers point to const Persons. So when I do something like this:
people[i] = &p;
where p is a reference to an object of type const Person, it fails.
const Person *people[10]Personwould bePerson* const people[10];.const Person *cannot change the person, but can point to other people.Person *constcan change the person, but can't point to anyone else. I feel I could make a joke here, but one eludes me. Putting the pointer into an array doesn't change that property of the pointer.const Person *==Person const *T," whereTis an array type, refers to an array whose elements are so-qualified. An array type whose elements are cv-qualified is also considered to have the same cv-qualifications as its elements."