jjones-99 / cs4500-sp2020-a1-part2-jones-tam

Jackie Tam and Jared Jones' work for Assignment 1: Part 2 of Software Development in Spring 2020.
0 stars 2 forks source link

Why we need String(String *const s) in string.h? #13

Closed angeliama98 closed 4 years ago

angeliama98 commented 4 years ago

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?

jjones-99 commented 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.

angeliama98 commented 4 years ago

ok. I see what you mean. Never mind.