C++ boost::utility::noncopyable














































C++ boost::utility::noncopyable



Introduction:

Boost::utility provides the class boost::noncopyable which makes it impossible to copy (and move) objects. The sole intention of this class is to make its objects non-copyable. It is used in places where confidential data is stored or where plagarism issues can arise.


Header file: boost/noncopyable.hpp


Syntax: 

 1. class class_name : boost::noncopyable  

     {

     };

 2. struct struct_name : boost::noncopyable

     {

     };


Example:

#include <boost/noncopyable.hpp> #include <string> #include <utility> #include <iostream> using namespace std; struct animal : boost::noncopyable { string name; int legs; animal(string n, int l) : name{move(n)}, legs{l} {} }; void print(const animal &a) { cout << a.name << '\n'; cout << a.legs << '\n'; } int main() { animal a{"cat", 4}; print(a); return 0; }


Output:



Comments