diff --git a/Char.cpp b/Char.cpp index e610e01..ec18d74 100644 --- a/Char.cpp +++ b/Char.cpp @@ -10,11 +10,11 @@ Char& Char::operator=(char other) { auto data = new char[_string.size() + 2]; // space for new char & null-terminator std::strcpy(data, _string.c_str()); - data[_index] = other; + data[_index] = other; // set the desired char - _string._str->operator--(); - _string._str = new StringValue(data); + _string._str->operator--(); // release old StringValue + _string._str = new StringValue(data); // make a new one return *this; } \ No newline at end of file diff --git a/Char.h b/Char.h index fb5cdc4..970a9fc 100644 --- a/Char.h +++ b/Char.h @@ -5,6 +5,9 @@ class StringValue; +// TODO: think about making ctors explict +/* This class provides a simple wrapper for a char primitive, and implements + * copy-on-write semantics for the non-const String::operator[] via some magic */ class Char { private: diff --git a/String.h b/String.h index 75eab5f..582b868 100644 --- a/String.h +++ b/String.h @@ -6,6 +6,7 @@ class Char; +// TODO: think about making ctors explict /* Design decisions: * - Everything related to ref-counting is the responsibility of the StringValue class * - Anything dynamically allocated is owned (and thus once deleted) by the StringValue class