阅读源码时,发现一个小知识点,关于boost::noncopyable类的,查看该类源码发现,其拷贝构造函数和拷贝复制运算符被禁用了,这样子类在继承时,子类的拷贝构造函数和拷贝复制运算符也会被禁用。
boost::noncopyable类源码如下:
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
};
为了验证这一点,写了一个demo,源码如下:
#include <iostream>
class Basic
{
public:
Basic() = defau