diff --git a/core/string.cpp b/core/string.cpp index a7cf450..d5570b4 100644 --- a/core/string.cpp +++ b/core/string.cpp @@ -604,6 +604,14 @@ bool operator!=(std::string &b, const String &a) { return !(a == b); } +String& String::operator=(const String &other) { + clear(); + + append_str(other); + + return *this; +} + String::String() { _data = nullptr; _actual_size = 0; @@ -695,5 +703,6 @@ String::String(const std::string &str) { String::~String() { if (_data) { delete[] _data; + _data = nullptr; } } diff --git a/core/string.h b/core/string.h index 4b90603..411ea7b 100644 --- a/core/string.h +++ b/core/string.h @@ -97,6 +97,8 @@ public: operator std::string() { return to_string(); } operator std::string() const { return to_string(); } + String& operator=(const String &other); + String(); String(const String &other); String(const String &other, const int grow_by);