class point{
public:
point():xval(0),yval(0){}
point(int x,int y):xval(x),yval(y){}
int x()const{return xval;}
int y()const{return yval;}
point& x(int xv){xval=xv;return *this;}
point& y(int yv){yval=yv;return *this;}
private:
int xval,yval;
};
class upoint{
friend class handle;
point p;
int u;
upoint():u(1){}
upoint(int xv,int yv):p(xv,yv){}
upoint(const point& p0):p(p0),u(1){}
};
///////////////////////////////////////////////////////
//handle.cpp
class handle{
public:
handle():vp(new upoint){}
handle(const point& p):vp(new upoint(p)){};
handle(const handle&);
handle(int xv,int yv):vp(new upoint(xv,yv)){}
handle& operator=(const handle& h);
~handle(){if(--vp->u==0)delete vp;}//{if(vp->u==0)delete vp;}
int x()const;
handle& x(int);
int y()const;
handle& y(int);
private:
upoint* vp;
//plus member here
}
//inline handle::handle():vp(new upoint){}
//inline handle::~handle(){if(--vp->u==0)delete vp;}
handle& handle::operator =(const handle &h)
{
++h.vp->u;
if(--vp->u==0)
delete vp;
vp=h.vp;
return *this;
}
int handle::y()const{return vp->p.y();}
inline int handle::x()const{return vp->p.x();}
inline handle& handle::x(int xv){vp->p.x(xv);return *this;}
inline handle& handle::y(int yv){vp->p.y(yv);return *this;}
//////////////////////////////////////////////////////////////////
#include
#include
using namespace std;
int main(){
point a;
handle p(a)
return 1;
}
--------------------next---------------------
阅读(1368) | 评论(0) | 转发(0) |