diff options
DynStr now accomodates terminating zeroes
1 files changed, 5 insertions, 5 deletions
| -rw-r--r-- | Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/DynStr.cpp | 10 |
diff --git a/Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/DynStr.cpp b/Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/DynStr.cpp index 4f4d52e..bac5c83 100644 --- a/Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/DynStr.cpp +++ b/Year 1/Object-oriented Programming/Solutions Sem. 08/ex3/DynStr.cpp @@ -4,7 +4,7 @@ /* Private */ void DynStr::free() { - if(str != nullptr) delete[] str; + delete[] str; } void DynStr::copyFrom(const DynStr& other) { @@ -17,13 +17,13 @@ void DynStr::copyFrom(const DynStr& other) { /* Public */ -DynStr::DynStr() { - str = nullptr; - length = 0; -} +DynStr::DynStr() : DynStr("") +{} DynStr::DynStr(const char* str) { int strLen = strlen(str); + strLen++; // Make space for \0 + this->str = new char[strLen]; strcpy(this->str, str); length = strLen; |
