#include <iostream>
class Point
{
public:
Point(int x,int y):x_(x),y_(y){}
Point(Point &point):x_(point.x_),y_(point.y_)
{}
~Point()
{
std::cout<<"This Point Has Been Released!\n";
}
int x() const
{
return x_;
}
int y()const
{
return y_;
}
Point & x(int xv)
{
this->x_=xv;
return *this;
}
Point & y(int yv)
{
this->y_=yv;
return *this;
}
private:
int x_;
int y_;
};
class Counter
{
public:
Counter(Counter & counter)
{
this->pCount=counter.pCount;
}
Counter():pCount(new int(1)){}
void retain()
{
(*pCount)++;
}
bool release()
{
if(*pCount==1)
{
delete this->pCount;
return false;
}
else
{
(*pCount)--;
return true
c++ 句柄样例代码(改自c++沉思录)
最新推荐文章于 2023-11-24 11:52:56 发布