What is the Bootloader
What is the Bootloader?
April 19, 2022
Kernel Module init and cleanup functions
Kernel Module init and cleanup functions
May 3, 2022

April 26, 2022

How to use derived class instance in a base class?

When trying to access a derived class functionality in a base class, Curiously Recurring Template Pattern (CRTP) provides a useful interface. Inheriting from a template base class, derived class is used as the template parameter of the base class. From the perspective of the base object, the derived object is itself, but downcasted.

template <typename T>
class Base
{
 public:
  void doSomething()
  {
   T& derived static_cast<T&> (*this); // use derived...
  }
};
class Derived public Base<Derived>
{
   //...
};
How to use derived class instance in a base class?
This website uses cookies to improve your experience. By using this website you agree to our Data Privacy Statement
Read more