What are the advantages of boost::noncopyable

前端 未结 11 1187
野性不改
野性不改 2020-11-27 14:10

To prevent copying a class, you can very easily declare a private copy constructor / assignment operators. But you can also inherit boost::noncopyable.

11条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 14:25

    Quoting the documentation:

    "The traditional way to deal with these is to declare a private copy constructor and copy assignment, and then document why this is done. But deriving from noncopyable is simpler and clearer, and doesn't require additional documentation."

    http://www.boost.org/libs/utility/utility.htm#Class_noncopyable

提交回复
热议问题