NonCopyable Class Reference

#include <Pt/NonCopyable.h>

Base class that disables copy construction and assignment. More...

Inherited by , , IConnector [private], Transaction [private], Deserializer [private], Style::Facet [private], Styler [private], PaintContext [private], PaintSurface [private], PainterBase [private], Authenticator [private], Authorization [private], Authorizer [private], Client [private], MessageHeader [private], Server [private], Service [private], Servlet [private], JsonFormatter [private], JsonReader [private], Formatter [private], Tool [private], ToolDeclaration [private], Type [private], MemoryPool, PageAllocator [protected], PoolAllocator [protected], , Client [private], , , Responder [private], Result< R > [private], ServiceDefinition [private], , Singleton< T >, , , Type [private], Certificate [private], Context, IOStream [private], Clock [private], Condition [private], EventSink [private], EventSource [private], LogChannel [protected], LogMessage [protected], LogRecord [protected], LogTarget [protected], Logger [protected], Mutex [private], MutexLock [private], Pipe, Process [private], ReadLock [private], ReadWriteMutex [private], RecursiveLock [private], RecursiveMutex [private], Selectable [protected], Semaphore [private], SpinLock [private], SpinMutex [private], Thread [protected], WriteLock [private], Reporter [protected], Test [protected], AttributeList [private], DocType [private], and DocTypeDefinition [private].

Public Member Functions

 NonCopyable ()
 Default constructor.
 ~NonCopyable ()
 Destructor.

Detailed Description

Inherit privately from NonCopyable when a type must not be copied. The copy constructor and assignment operator are private, so a derived class cannot copy or assign, and neither can a caller. The result is a compile-time error, not a run-time failure.

class MyClass : private Pt::NonCopyable
{
// ...
};
Base class that disables copy construction and assignment.
Definition NonCopyable.h:59

Private inheritance is the usual form: NonCopyable is not part of the public interface. Public inheritance also prevents copies, but it exposes the mixin as a base. Do not try to make a type copyable again in a further derived class; the private members of NonCopyable stay private. Types that need to be moved but not copied still inherit here and define their own move operations.