Hi,
The following code doesn't work:
class String{
public:
char* str;
int* counter;
String(){
str = NULL;
counter = new int;
*counter = 1;
};
String(const char* str1){
String();
str = new char[strlen(str1)+1];
strcpy(str, str1);
};
};
I've changed the call to the empty constructor and replaced it with its internals, and now the following code works:
class String{
public:
char* str;
int* counter;
String(){
str = NULL;
counter = new int;
*counter = 1;
};
String(const char* str1){
//String();
str = new char[strlen(str1)+1];
strcpy(str, str1);
counter = new int;
*counter = 1;
};
Can you please suggest why?
Thanks, Li.