I'd have to agree with Richard a take a look at what
RemoveLastChar
is doing. If I strip your String class down to the bare essentials needed for your question, then things work fine
#include <iostream>
#include <string>
class C {
public:
std::string data;
C(const char* str) : data(str) {}
C() = default;
C& operator=(const char *str) {
data = str;
return *this;
}
C& operator=(const C& other) {
data = other.data;
return *this;
}
};
int main()
{
C a = "Hello";
std::cout << "a = '" << a.data << "'\n";
a = "Goodbye";
std::cout << "a ='" << a.data << "'\n";
C b[3];
b[0] = a;
std::cout << "b[0] = '" << b[0].data << "'\n";
b[1] = "foobar";
std::cout << "b[1] ='" << b[1].data << "'\n";
}
which produces the expected output, and does not crash
a = 'Hello'
a ='Goodbye'
b[0] = 'Goodbye'
b[1] ='foobar'
you could try a version of your class without the tests using RemoveLastChar() function call and see if that works better. You'll then know if RemoveLastChar() is the culprit or not. If not, then its probably time to delve into the debugger.