175. Template

Question.13

A developer uses the Curiously Recurring Template Pattern:

template<typename Derived>
class IDriver {
public:
   void init() {
       static_cast<Derived*>(this)->hw_init();
   }
};

class UART : public IDriver<UART> {
public:
   void hw_init() { /* UART registers */ }
};

UART u;
u.init();  // Calls UART::hw_init()

How does this differ from virtual function polymorphism?

Need Help? Refer to the Quick Guide below

Select Answer