Apparently, a const member function is still allowed to change data that the class member are pointing to. Here\'s an example of what I mean:
class MyClass
{
There is no way to do what you want. Your const member function can't change the value of data (the address it points to), but there is nothing about not changing the contents it points to as you have already noticed. Using a std::vector
would help, since within a const member function you would actually have a const vector, not being able to call any of its mutable functions.