Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2350767
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:02:25

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) |
给主人留下些什么吧!~~