I want to initialize a char* string, inside a struct.
this is the struct:
typedef struct __String {
char* data; // C-string data,
unsigned* copyRef; // number of copy reference, delete only when the copyRef is 0
bool isACopy; // this boolean is true when *data is a ref to an other MyString
__String () {
data = 0;
isACopy = false;
copyRef = new unsigned();
*copyRef = 0;
return;
}
void addCopyRef() {
*copyRef++;
}
void removeCopyRef() {
*copyRef--;
}
} *MyString;
and this is the point where it chrash..
void Initialize(MyString& string){
string->data = new char[LENGHT];
string->data[0] ='\0'; // this generate an error!
string->addCopyRef();
}
this is the main:
MyString left_string, right_string, both_string;
Initialize(left_string);
Initialize(right_string);
Initialize(both_string);
the first one is going well, the second not.. could please you help me to understand where is the problem? thanks!