loosing the first element of an array
I call this function to assign a MyString object to another but I end up losing the first value somehow.
If you need some other part of the code here is a GitHub repo
https://github.com/MarkFuller1/Project_1.5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
MyString &MyString::operator=(const MyString &input) {
while (input.data[++charCount] != '\0') {
if (charCount >= this->capacity) {
auto *temp = new char[this->capacity * 2];
this->capacity *= 2;
for (int j = 0; j < charCount; j++) {
temp[j - 1] = this->data[j];
}
delete[] this->data;
this->data = temp;
}
this->data[charCount] = input.data[charCount];
}
size = charCount;
return *this;
}
|
Last edited on
SOLVED: line 8, temp[j - i] should be just temp[j]
Topic archived. No new replies allowed.