#include <algorithm>
#include <cstring>
#include <iostream>

class A
{
    public:
       // construct from string
       A () : str(new char[1]()) {}

       A(const char *s) : str(new char[strlen(s) + 1])
       { strcpy(str, s); }
       
       // copy construct
       A(const A& rhs) : str(new char[strlen(rhs.str) + 1])
       { strcpy(str, rhs.str); }

       // destruct
       ~A() { delete []  str; }

       // assign
       A& operator=(const A& rhs)
       {
          A temp(rhs);
          std::swap(str, temp.str);
          return *this;
       }

       // implement
       void setStr(char * s)
       {
          A temp(s);
          *this = temp;
       }  

       const char* getStr() { return str; }
       
     private:
        char * str;
};

using namespace std;

int main()
{
	A a1;
	a1.setStr("abc");
	A a2;
	a2 = a1;
	A a3 = a1;
	a2.setStr("456");
	cout << a1.getStr() << "\n" << a2.getStr() << "\n" << a3.getStr();
}
	
