The task is to write your class "String". Faced such a problem: during program execution error " Expression:CrtlsValidHeapPointer(block) ".
I suppose there is an error somewhere in constructors or assignments, but I can't figure it out.
#include <cstring> #include <iostream> class my_string { private: int length; char *symbols; public: my_string() { length = 0; symbols = new char[100]; } ~my_string() { delete symbols; } my_string(const my_string& s) { length = s.length; symbols = new char(*s.symbols); } my_string my_string::operator=(const my_string& s) { length = s.length; symbols = new char(*s.symbols); return *this; } my_string my_string::operator+=(const my_string& s) { my_string tmp; delete tmp.symbols; length = strlen(symbols) + strlen(s.symbols); tmp.symbols = new char[length + 1]; strcpy(tmp.symbols, symbols); strcat(tmp.symbols, s.symbols); delete symbols; symbols = new char[length + 1]; strcpy(symbols, tmp.symbols); delete tmp.symbols; return *this; } bool my_string::operator==(const my_string& s) { if (strcmp(symbols, s.symbols)) return false; else return true; } my_string clean_string() { delete symbols; my_string(); return *this; } }; I enter the data in the symbols with the help of std::cin>>symbols , but removed it so as not to litter the code