diff --git a/Char.cpp b/Char.cpp new file mode 100644 index 0000000..e610e01 --- /dev/null +++ b/Char.cpp @@ -0,0 +1,20 @@ +#include "Char.h" +#include + + + +Char::operator char() const +{ return _string._str->operator[](_index); } + +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; + + + _string._str->operator--(); + _string._str = new StringValue(data); + + return *this; +} \ No newline at end of file diff --git a/Char.h b/Char.h new file mode 100644 index 0000000..fb5cdc4 --- /dev/null +++ b/Char.h @@ -0,0 +1,20 @@ +#pragma once +#include "String.h" +class String; +class StringValue; + + + +class Char +{ +private: + + size_t _index; + String& _string; + +public: + + Char(size_t index, String& string) :_index(index), _string(string) {} + operator char() const; + Char& operator=(char other); +}; \ No newline at end of file