Projekt

Allgemein

Profil

Feature #818

Add class for CRTP

Von Maximilian Seesslen vor etwa 10 Stunden hinzugefügt.

Status:
Neu
Priorität:
Normal
Zugewiesen an:
Zielversion:
-
Beginn:
08.07.2026
Abgabedatum:
% erledigt:

0%

Geschätzter Aufwand:
CS Zielversion:

Beschreibung

Curiously Recurring Template Pattern: statischen Polymorphismus

#define CRTP_METHOD(name, args...) \
void name() \ { \
derived().name##_impl( , ##args ); \
}

// VA_ARGS

#define CRTP_HELPERS(Derived) \
Derived& derived() \ { \
return static_cast<Derived&>(*this); \
} \
\
const Derived& derived() const \ { \
return static_cast<const Derived&>(*this); \
}

template<class Derived>
class CClassA {
CRTP_HELPERS(Derived);

public:
CRTP_METHOD(name, int i1, int i2);
void callback()
   {
name();
}
};

class CClassB;

class CClassB :public CClassA < CClassB > {
public:
void name_impl() {
printf("Callback\n");
}
};

Auch abrufbar als: Atom PDF