Feb 11, 2012 at 6:05am UTC
Make getName() return a const char*.
Last edited on Feb 11, 2012 at 6:06am UTC
Feb 11, 2012 at 7:53am UTC
So do need the const at the beginning and end or just the beginning
Feb 11, 2012 at 5:28pm UTC
the assignment told me to return a c-string so didn't have that option, but it works when returning a const char like Peter said. Im a little confused as of why though
Last edited on Feb 11, 2012 at 5:28pm UTC
Feb 11, 2012 at 7:59pm UTC
1) A pointer is not an array. It is a number (representing a memory address, which is why we say it points to somewhere).
2) So when you write const char *p
you mean "pointer p will not modify the data where it points".
3) By putting const behind a member function, it means that it doesn't modify the data of the class.
So that's why you use a const pointer, which guarantees... sigh... that it won't allow the data it points to, to be modified.