char* Student::getFirstName() const {
return firstName; //Error code here says...
} //Cannot initialize return object of type 'char *' with
//an lvalue of type 'char const[16]'
Yes, when returning a pointer or reference to something that is stored inside the object you normally want it to be const if the function is marked const, otherwise it provides a way of modifying the object even when you are not supposed to.
1 2 3 4 5 6 7 8
// This function promise not to modify the student object that is passed to it.
void foo(const Student& student)
{
// But if getLastName() returned a pointer to a non-const char there would
// be nothing preventing you from making changes to the student's name.
char* str = student.getLastName();
str[0] = 'A'; //The student's name now starts with an A.
}