#include <iostream>
#include <string.h>
using namespace std;
class Cwin
{
private:
char id,*title;
public:
Cwin(char i='D',char *text="default windows")
{
id=i;
cout<<"件構元被呼叫....."<<endl;
title=new char[strlen(text)+1];
strcpy(title,text);
}
Cwin(const Cwin &win) //拷貝運算元
{
cout<<"拷貝建構元被呼叫...."<<endl;
id=win.id;
title=win.title;
strcpy(title,win.title);
}
~Cwin()
{
delete [] title;
}
void show()
{
cout<<"Windows= "<<id<<" : "<< title <<endl;
}
};
int main()
{
Cwin *ptr1=new Cwin('A',"主要的視窗");
Cwin *ptr2=new Cwin(*ptr1);
ptr1->show();
ptr2->show();
delete ptr1;
cout<<"刪除prt1之後..."<<endl;
ptr2->show();
delete ptr2;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY2xhc3MgQ3dpbgp7CiAgICBwcml2YXRlOgogICAgICAgIGNoYXIgaWQsKnRpdGxlOwogICAgcHVibGljOgogICAgICAgIEN3aW4oY2hhciBpPSdEJyxjaGFyICp0ZXh0PSJkZWZhdWx0IHdpbmRvd3MiKQogICAgICAgIHsKICAgICAgICAgICAgaWQ9aTsKICAgICAgICAgICAgY291dDw8IuS7tuani+WFg+iiq+WRvOWPqy4uLi4uIjw8ZW5kbDsKICAgICAgICAgICAgdGl0bGU9bmV3IGNoYXJbc3RybGVuKHRleHQpKzFdOwogICAgICAgICAgICBzdHJjcHkodGl0bGUsdGV4dCk7CiAgICAgICAgfQogICAgICAgIEN3aW4oY29uc3QgQ3dpbiAmd2luKSAvL+aLt+iynemBi+eul+WFgwogICAgICAgIHsKICAgICAgICAgICAgY291dDw8IuaLt+iyneW7uuani+WFg+iiq+WRvOWPqy4uLi4iPDxlbmRsOwogICAgICAgICAgICBpZD13aW4uaWQ7CiAgICAgICAgICAgIHRpdGxlPXdpbi50aXRsZTsKICAgICAgICAgICAgc3RyY3B5KHRpdGxlLHdpbi50aXRsZSk7CiAgICAgICAgfQogICAgICAgIH5Dd2luKCkKICAgICAgICB7CiAgICAgICAgICAgIGRlbGV0ZSBbXSB0aXRsZTsKICAgICAgICB9CiAgICAgICAgdm9pZCBzaG93KCkKICAgICAgICB7CiAgICAgICAgICAgIGNvdXQ8PCJXaW5kb3dzPSAiPDxpZDw8IiA6ICI8PCB0aXRsZSA8PGVuZGw7CiAgICAgICAgfQp9OwppbnQgbWFpbigpCnsKICAgIEN3aW4gKnB0cjE9bmV3IEN3aW4oJ0EnLCLkuLvopoHnmoToppbnqpciKTsKICAgIEN3aW4gKnB0cjI9bmV3IEN3aW4oKnB0cjEpOwoKICAgIHB0cjEtPnNob3coKTsKICAgIHB0cjItPnNob3coKTsKCiAgICBkZWxldGUgcHRyMTsKICAgIGNvdXQ8PCLliKrpmaRwcnQx5LmL5b6MLi4uIjw8ZW5kbDsKCiAgICBwdHIyLT5zaG93KCk7CiAgICBkZWxldGUgcHRyMjsKICAgIHJldHVybiAwOwp9Cg==