C++不可拷貝基類實現

#ifndef NONCOPYABLE_HPP
#define NONCOPYABLE_HPP

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

class noncopyable
{
protected:
#if __cplusplus >= 201103L
      constexpr noncopyable() = default;
      ~noncopyable() = default;
#else
      noncopyable() {}
      ~noncopyable() {}
#endif
#if __cplusplus >= 201103L
      noncopyable( const noncopyable& ) = delete;
      noncopyable& operator=( const noncopyable& ) = delete;
#else
private:  // emphasize the following members are private
      noncopyable( const noncopyable& );
      noncopyable& operator=( const noncopyable& );
#endif
};

#endif//NONCOPYABLE_HPP

C++不可拷貝基類的實現,學習自BOOST庫

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章