Originally Posted by
Lindley
Your present approach of using a fixed-size char array is better than what you had in the first post, but it's not ideal. You haven't done any checks for whether the passed string will fit in the array you have available, and your object will be much larger than necessary for small strings.
What you really want to do is dynamically allocate the memory necessary to copy the passed in string. However, doing this brings along several additional responsibilities:
1) You must release the allocated memory in the destructor.
2) You must ensure you allocate a different block of memory when copying, not just copy the pointer. (Unless you want to do reference counting, but that's even more difficult.)
3) If your string is reassigned to be longer, you must modify your allocation safely to be able to handle the new value.