0

Possible Duplicate:
What are the advantages of boost::noncopyable

Why there is boost::noncopyable, I understand this gives a feature that no copy can be make for the class which is child of boost::noncopyable, but this can be easily done having private copy constructor and assignment operator

What is the need to haveing separate class and inheriting it to your class.

Community
  • 1
  • 1
Avinash
  • 12,851
  • 32
  • 116
  • 186
  • Note that most of the discussion in this duplicate is completely out of date in the presence of C++11. As Howard Hinnant posted, the new alternative `Object(Object const&) = delete;` is extremely clear. – Matthieu M. Feb 14 '12 at 08:10

1 Answers1

2

I think it's for readability.

Not everybody knows about the goal of privating c-ctor and assignment operator. boost::noncopyable represents what it does.

Inbae Jeong
  • 4,053
  • 25
  • 38
  • I would say it's also a lot less biolerplate code to write. Inheriting from `boost::noncopyable` declares intent much more succinctly. – Alexander Kondratskiy Feb 14 '12 at 06:24
  • 1
    And also private inheritance prevents friend classes from being allowed to access the private copy functions, which would convert compile time errors into link time errors. Having to declare your own non-copyable class every time would be even more boilerplate. – bames53 Feb 14 '12 at 07:09