论坛首页 编程语言技术论坛

boost笔记2

浏览 1512 次
锁定老帖子 主题:boost笔记2
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-07-28  
C++

看到boost中noncopyable,基本思想很简单,无非把拷贝构造和赋值运算符声明为private并且不加以实现。
比较特殊的是noncopyable的实现中定义了noncopyable_名字空间,然后再将noncopyable使用typedef定义。

 

#ifndef BOOST_NONCOPYABLE_HPP_INCLUDED
#define BOOST_NONCOPYABLE_HPP_INCLUDED

namespace boost {

//  Private copy constructor and copy assignment ensure classes derived from
//  class noncopyable cannot be copied.

//  Contributed by Dave Abrahams

namespace noncopyable_  // protection from unintended ADL
{
  class noncopyable
  {
   protected:
      noncopyable() {}
      ~noncopyable() {}
   private:  // emphasize the following members are private
      noncopyable( const noncopyable& );
      const noncopyable& operator=( const noncopyable& );
  };
}

typedef noncopyable_::noncopyable noncopyable;

} // namespace boost

 

ADL是Argument Dependent Lookup的缩写,其实就是Koenig Lookup。
namespace noncopyable_ {
//..................
}

typedef noncopyable_::noncopyable noncopyable,
这样写是把noncopyable的具体实现定一个一个单独的名字空间内,
起到了和boost名字空间隔离的作用。

论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics