Alright, I know a class can access its own private members and nothing else can, but what if I wanted to return a private member using a public method? For example, I create an array of chars in a class which are private. The end-developer may need to view this data for some reason. I return a pointer to that array through a public method. Could the developer use the pointer to change that data, or just read it?
this->pBuffer = new char;
sprintf(this->pBuffer, "This is a pointless message! ");
//Somewhere in the main program loop...
pTemp = new MyFakeClass;
pText = pTemp->ReturnMessage();
sprintf(pText, "This should cause an error! ");
Would the sprintf() call crash the program or throw an exception as it should, or will it simply overwrite the text in the array, which it shouldn't?