C++ 知道禁用 copy-ctor/assign operator 是 C++ 程序员的试金石
2015-10-12 21:09
531 查看
陈硕CSDN博客 :知道禁用 copy-ctor/assign operator 是 C++ 程序员的试金石
vgxpm的专栏:C++之实现禁用 copy-ctor/assign operator : 对其进行了解释,详细阅读
陈硕github/muduo : Singleton.h 的实现中对其对copy-ctor/assign operator进行禁用,利用继承noncopyable,代码:
boost/core/noncopyable.hpp
vgxpm的专栏:C++之实现禁用 copy-ctor/assign operator : 对其进行了解释,详细阅读
陈硕github/muduo : Singleton.h 的实现中对其对copy-ctor/assign operator进行禁用,利用继承noncopyable,代码:
class Singleton : boost::noncopyable
boost/core/noncopyable.hpp
// Boost noncopyable.hpp header file --------------------------------------// // (C) Copyright Beman Dawes 1999-2003. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // See http://www.boost.org/libs/utility for documentation. #ifndef BOOST_CORE_NONCOPYABLE_HPP #define BOOST_CORE_NONCOPYABLE_HPP #include <boost/config.hpp> 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: #if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) && !defined(BOOST_NO_CXX11_NON_PUBLIC_DEFAULTED_FUNCTIONS) BOOST_CONSTEXPR noncopyable() = default; ~noncopyable() = default; #else noncopyable() {} ~noncopyable() {} #endif #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) 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 }; } typedef noncopyable_::noncopyable noncopyable; } // namespace boost #endif // BOOST_CORE_NONCOPYABLE_HPP
相关文章推荐
- C语言windows目录操作
- 2、C语言关键字-auto register static
- tuple元组(C++11及以后,如C++14)
- 并查集的树形实现(C++)(转载)
- 项目36.2 转着圈加密
- 利用模拟退火算法求解TSP问题(C++实现)
- 哈夫曼树——C++实现
- C++对C的扩充(体现在面向过程程序设计部分)
- 顺序栈——C++实现
- 单链表的复制——C++实现
- C#基本知识点,与C++不同点
- 单链表的基本操作——C++实现
- 约瑟夫环问题(顺序表)——C++实现
- 顺序表求集合交并——C++实现
- 项目36.1M$pszi$y是嘛意思?
- C语言学习
- 1、C语言基本数据类型
- C++ STL学习笔记十二 hash_map映照容器
- C++ STL学习笔记十 multimap多重映照容器
- C++ STL学习笔记十一 hash_set哈希集合容器