Lets declare a class 'Demo'
class Demo { private: char a; void TestConst(char* const pData)const { // pData = "test"; // char* const protects // pData++; // pointer! // a = 'a'; // const for function // protects data member. } };So, when we are working with C++, all data members irrespective of access specification, can be protected with 'const', appended to the declaration/definition.
Comments
Is that correct ?
First, char *const pData means pData is a const pointer to char. We can't change the pointer itself.
Second TestConst is a const function. const function does not allow any modification of member variables, though member variable(s)is/are not const.