Implementation of the Curiously Recurring Template Pattern (CRTP). CRTP achieves static polyphormism by offerings access to the derived class within the base class.
More...
#include <CRTP.h>
|
| | CRTP () |
| | The default constructor.
|
|
| Derived & | derived () |
| | A reference to the derived object.
|
| Derived * | p_derived () |
| | A pointer to the derived object.
|
| const Derived & | derived () const |
| | A reference to the const derived object.
|
| const Derived * | p_derived () const |
| | A pointer to the const derived object.
|
template<typename Derived>
class model::CRTP< Derived >
Implementation of the Curiously Recurring Template Pattern (CRTP). CRTP achieves static polyphormism by offerings access to the derived class within the base class.
Definition at line 18 of file CRTP.h.
◆ CRTP()
template<typename Derived>
The default constructor.
Sample use:
#include <iostream>
template <typename Derived>
class BaseClass :
public CRTP<Derived>{
public:
void print()
const {std::cout<<
"Base class of DerivedClass"<< this->
p_derived()->id()<<std::endl;}
};
class DerivedClass1 : public BaseClass<DerivedClass1>{
public:
int id() const {return 1;}
};
class DerivedClass2 : public BaseClass<DerivedClass2>{
public:
int id() const {return 2;}
};
DerivedClass1 dc1;
DerivedClass2 dc2;
dc1.print();
dc2.print();
}
Derived * p_derived()
A pointer to the derived object.
CRTP()
The default constructor.
int main(int argc, char **argv) int main(argc
Definition at line 37 of file CRTP.h.
◆ derived() [1/2]
template<typename Derived>
A reference to the derived object.
Definition at line 24 of file CRTP.h.
◆ derived() [2/2]
template<typename Derived>
| const Derived & model::CRTP< Derived >::derived |
( |
| ) |
const |
|
inlineprotected |
A reference to the const derived object.
Definition at line 30 of file CRTP.h.
◆ p_derived() [1/2]
template<typename Derived>
A pointer to the derived object.
Definition at line 27 of file CRTP.h.
◆ p_derived() [2/2]
template<typename Derived>
| const Derived * model::CRTP< Derived >::p_derived |
( |
| ) |
const |
|
inlineprotected |
A pointer to the const derived object.
Definition at line 33 of file CRTP.h.
The documentation for this class was generated from the following file: