Closed angeliama98 closed 4 years ago
This constructor is just a copy constructor, which is a common occurrence in classes. It just creates a new String by copying the given. Without it, there isn't any way to copy a String without saying something like new String(some_string->private_char_array_)
, and we don't want to force the user to use a private field.
(I did just add the get()
method that returns a char*
representing the String, so this could be done with new String(some_string->get())
, now. But still, the copy constructor is neater.)
What do you by, "We should be able to get access to the string or make a copy of it if we need to implement it in a specific way?" I'm not sure if I understand what you are trying to say.
ok. I see what you mean. Never mind.
I'm kind of curious why we need String(String *const s). We should be able to get access to the string or make a copy of it if we need to implement it in a specific way. Could we remove this constructor?