I have a problem with my code. I get an error of BLOCK_TYPE_IS_VALID... I know there is problem with new and delete, but I cannot find it. I have a myString class with these functions:
//constructors and destructors
myString::myString() {
this->string_ = NULL;
this->length = 0;
cout << "created " << "NULL" << endl;
}
myString::myString(char a[]) {
int i;
for (i=0; a[i]!=NULL; i++);
this->length = i;
int j=0;
while(pow(2,j)<i)
j++;
this->string_ = new char [(int)pow(2,j)];
for (int i=0; i<this->length; i++)
this->string_[i] = a[i];
cout << "created " << this->string_ << endl;
}
myString::~myString() {
cout << "deleteing " << this->string_ << endl;
if (this->string_ != NULL)
delete [] this->string_;
}
and when I run this
myString a("aaa");
myString b("bbbb");
myString c;
c = a + b;
cout << c.get_lenght() << endl;
cout << c.get_string() << endl;
I get the error in line "c = a+b" and then program stops.