samedi 1 juin 2019

How to specialize constructor of template class in another class?

Consider the following classes:

// Class1.hpp
class1 {};

// Class2.hpp
class2 {};

// ClassA.hpp
#include "Class1.hpp"
#include "Class2.hpp"

class A {
    private:
    enum class Enum {
        Enum1,
        Enum2
    };

    struct B {
        B(Enum argEum) : enum{argEnum} {}
        Enum enum;
    };

    template <class T>
    struct C : public B {}
}

Now I would like to make the following specializations of the constructor of C:

C<Class1>::C() : B{Enum::Enum1} {}
C<Class2>::C() : B{Enum::Enum2} {}

From what I tried I guess I have to place the specializations outside of the class definition of class A, but I don't really know how to do it.

Aucun commentaire:

Enregistrer un commentaire