Documentation of SFML 2.5.0

Warning: this page refers to an old version of SFML. Click here to switch to the latest version.
sf::NonCopyable Class Reference

Utility class that makes any derived class non-copyable. More...

#include <NonCopyable.hpp>

Inheritance diagram for sf::NonCopyable:
sf::Context sf::Cursor sf::FileInputStream sf::Ftp sf::GlResource::TransientContextLock sf::Http sf::InputSoundFile sf::Lock sf::Mutex sf::OutputSoundFile sf::RenderTarget sf::Shader sf::Socket sf::Thread sf::ThreadLocal sf::Window

Protected Member Functions

 NonCopyable ()
 Default constructor. More...
 
 ~NonCopyable ()
 Default destructor. More...
 

Detailed Description

Utility class that makes any derived class non-copyable.

This class makes its instances non-copyable, by explicitly disabling its copy constructor and its assignment operator.

To create a non-copyable class, simply inherit from sf::NonCopyable.

The type of inheritance (public or private) doesn't matter, the copy constructor and assignment operator are declared private in sf::NonCopyable so they will end up being inaccessible in both cases. Thus you can use a shorter syntax for inheriting from it (see below).

Usage example:

class MyNonCopyableClass : sf::NonCopyable
{
...
};

Deciding whether the instances of a class can be copied or not is a very important design choice. You are strongly encouraged to think about it before writing a class, and to use sf::NonCopyable when necessary to prevent many potential future errors when using it. This is also a very important indication to users of your class.

Definition at line 41 of file NonCopyable.hpp.

Constructor & Destructor Documentation

◆ NonCopyable()

sf::NonCopyable::NonCopyable ( )
inlineprotected

Default constructor.

Because this class has a copy constructor, the compiler will not automatically generate the default constructor. That's why we must define it explicitly.

Definition at line 53 of file NonCopyable.hpp.

◆ ~NonCopyable()

sf::NonCopyable::~NonCopyable ( )
inlineprotected

Default destructor.

By declaring a protected destructor it's impossible to call delete on a pointer of sf::NonCopyable, thus preventing possible resource leaks.

Definition at line 63 of file NonCopyable.hpp.


The documentation for this class was generated from the following file: