#include <iostream>
#include <cstdlib>
#include <cstring>

using namespace std;
class CWin
{
   protected:
     char id;

   public:
     CWin(char i='D'):id(i)
     {

     }
     CWin(const CWin& win)
     {
        id=win.id;
     }
};

class CTextWin : public CWin
{
   private:
      char *text;

   public:
      CTextWin(char i, const char *tx):CWin(i)
      {
         text= new char[strlen(tx)+1];
         strcpy(text,tx);
      }
      ~CTextWin()
      {
         delete [] text;
      }
      void show_member()
      {
         cout << "Window " << id << ": ";
         cout << "text = " << text << endl;
      }
      void set_member(char i, const char *tx)
      {
         id=i;
         delete [] text;
         text= new char[strlen(tx)+1];
         strcpy(text,tx);
      }
};
int main(void)
{
   CTextWin tx1('A',"Hello C++");
   CTextWin tx2(tx1);

   tx1.show_member();
   tx2.show_member();

   cout << "更改tx1物件的成員之後..." << endl;
   tx1.set_member('B',"Welcome  C++");

   tx1.show_member();
   tx2.show_member();

   system("pause");
   return 0;
}