From d5bf0fd7d55dbe6c2c8d5228e7d531128298a8c0 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 15 Apr 2022 08:09:12 +0300 Subject: DynStr now accomodates terminating zeroes --- .../Solutions Sem. 08/ex3/DynStr.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Year 1/Object-oriented Programming') 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; -- cgit v1.3.1-23-gd82d