pImpl
pImpl Idiom in C++
Loading...
Searching...
No Matches
Singleton< T >

Singleton class. More...

#include <singleton.h>

Collaboration diagram for Singleton< T >:

Public Member Functions

 Singleton (const Singleton &)=delete
 Make the class non construction-copyable and non copyable.
 
Singletonoperator= (const Singleton)=delete
 Make the class non copyable.
 

Static Public Member Functions

static T & instance ()
 Get the instance object.
 

Protected Member Functions

 Singleton ()
 

Detailed Description

template<typename T>
class Singleton< T >

Singleton class.

How to use:

class Foo : public Singleton<Foo> {
friend class Singleton<Foo>;
public:
// No need to define a constructor, destructor, copy constructor and assignment operator
void bar() { ... }
private:
Foo() {}
};
Singleton class.
Definition singleton.h:30
Template Parameters
Tthe class to be singleton

Definition at line 30 of file singleton.h.

Constructor & Destructor Documentation

◆ Singleton() [1/2]

template<typename T >
Singleton< T >::Singleton ( const Singleton< T > &  )
delete

Make the class non construction-copyable and non copyable.

◆ Singleton() [2/2]

template<typename T >
Singleton< T >::Singleton ( )
inlineprotected

Definition at line 49 of file singleton.h.

Member Function Documentation

◆ instance()

template<typename T >
T & Singleton< T >::instance ( )
static

Get the instance object.

Returns
T& The unique instance

Definition at line 53 of file singleton.h.

◆ operator=()

template<typename T >
Singleton & Singleton< T >::operator= ( const Singleton< T >  )
delete

Make the class non copyable.