#include #include using namespace std; class MyString { private: char* pString; public: MyString(const char* pText) { pString = new char[ strlen(pText) + 1 ]; strcpy(pString, pText); } ~MyString() { cout << endl << "Destructor was called..." << endl; delete[] pString; } MyString& operator=(const MyString &String) { cout << endl << "calling = " << endl << endl; if(this == &String) return *this; delete[] pString; pString = new char[ strlen(String.pString) + 1]; // Copy right operand string to left operand strcpy(this->pString, String.pString); return *this; } char* getString() const { return pString; } }; int main() { MyString one("This is String 1"); MyString two("Another String 2"); cout << one.getString(); cout << endl; cout << two.getString(); cout << endl; one = two; cout << one.getString(); cout << endl; cout << two.getString(); getchar(); return 0; }