Disallow any member function to change its data members in C++ Class -
How can I do this? After starting the object in C ++, any member function can change the value of its data members.
All members work const
This is the only mechanism for the job, and It works just fine. If you also make them private
, then you are completely covered.
If for some reason you feel compelled to keep them safe, then things are more complicated.
You will need to create a personal area const
, and this will require you to start with the member initial list, or const_cast
in the constructor Or maybe a temporary whistle, but I'm not sure there is such a thing.
Comments
Post a Comment