I have a class String and I've made a field char* name, default, parameterized, copy constructor, destructor and overwritten operator =.
My question is how my default constructor should look like for a char*.
Below is part of my code. I use char* because the array should be dynamic:
class String {
public:
char* name;
String(){
name = new char[0];
}
String(char* str){
name = new char[strlen(str) + 1];
strcpy(name, str);
}
You can make a null-terminated array of length one. Also note that you should use member initializer list as shown below: