vendredi 18 octobre 2019

CRTP multiple level inheritance instantiate intermediate class with another template parameter

Given a multi level inheritance CRTP class structure like so, where the intermediate class B has another template parameter T, how should I instantiate an object of B?

template<class Derived, class T>
struct A {
    void print(T t) { static_cast<Derived*>(this)->print(t); }
};

template<template <typename> class Derived, class T>
struct B : public A<Derived<T>, T> {
    void print(T t) { cout << t << " B!\n"; }
};

template<class T>
struct C : public B<C, T> {
    void print(T t) { cout << t << " C!\n"; }
};

int main() {
    C<int> c;
    c.print(5);

    // how do I instantiate a B?
}

Aucun commentaire:

Enregistrer un commentaire