qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches

Base class to make derived classes non-copyable. More...

#include <nocopy.h>

Inheritance diagram for qb::nocopy:

Public Member Functions

 nocopy ()=default
 Default constructor.
 nocopy (nocopy const &)=delete
 Deleted copy constructor.
 nocopy (nocopy const &&)=delete
 Deleted move constructor.
nocopyoperator= (nocopy const &)=delete
 Deleted copy assignment operator.
nocopyoperator= (nocopy &&)=delete
 Deleted move assignment operator.

Detailed Description

Base class to make derived classes non-copyable.

Classes that inherit from this struct (usually via private inheritance) will have their copy constructor and copy assignment operator deleted, effectively preventing instances of the derived class from being copied. Their move constructor and move assignment operator are also deleted here to enforce non-movable semantics by default as well, unless explicitly re-enabled by the derived class.

This is useful for classes that manage unique resources (like file handles, network connections, or actor identities) where copying would be complex, semantically incorrect, or resource-intensive.

Usage example:

class MyResourceWrapper : private qb::nocopy {
public:
MyResourceWrapper() { // acquire resource }
~MyResourceWrapper() { // release resource }
// ... other methods ...
};
// MyResourceWrapper obj1;
// MyResourceWrapper obj2 = obj1; // Compile error: copy constructor is deleted
// obj1 = obj2; // Compile error: copy assignment is deleted
Base class to make derived classes non-copyable.
Definition nocopy.h:60

Constructor & Destructor Documentation

◆ nocopy() [1/3]

qb::nocopy::nocopy ( )
default

Default constructor.

Allows derived classes to be default-constructed if appropriate.

◆ nocopy() [2/3]

qb::nocopy::nocopy ( nocopy const & )
delete

Deleted copy constructor.

Prevents copying of derived class instances.

◆ nocopy() [3/3]

qb::nocopy::nocopy ( nocopy const && )
delete

Deleted move constructor.

Prevents moving of derived class instances by default.

Member Function Documentation

◆ operator=() [1/2]

nocopy & qb::nocopy::operator= ( nocopy const & )
delete

Deleted copy assignment operator.

Prevents copy assignment of derived class instances.

◆ operator=() [2/2]

nocopy & qb::nocopy::operator= ( nocopy && )
delete

Deleted move assignment operator.

Prevents move assignment of derived class instances by default.