posts - 183,  comments - 10,  trackbacks - 0

boost 中的 noncopyable

// boost
class noncopyable
{
protected:
 noncopyable() {}
 ~noncopyable() {}
private:
 noncopyable(const noncopyable&);
 const noncopyable& operator = (const noncopyable&);
};

class test : public noncopyable
{
};

int main()
{
 test a, b;
 // test b(a);
 // c = a;
}

这是通过继承的方式来实现的 noncopy

也可以通过组合的方式

class noncopyable
{
public:
 noncopyable() {}
 ~noncopyable() {}
private:
 noncopyable(const noncopyable&);
 const noncopyable& operator = (const noncopyable&);
}

class test
{
private:
 noncopyable noncopyable_;
};

int main()
{
 test a, c;
 // test b(a);
 // c = a;
}

http://www.cppblog.com/luke/archive/2009/03/13/76411.html
http://ebenzhang.blogbus.com/tag/noncopyable/
http://hi.baidu.com/jrckkyy/blog/item/e6b241de1645735f95ee37de.html
http://hi.baidu.com/jrckkyy/home
http://blog.csdn.net/alai04/article/details/577798
http://www.boost.org/doc/libs/1_47_0/boost/noncopyable.hpp

 

posted on 2011-07-23 22:07 unixfy 阅读(427) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理