mercredi 3 avril 2019

Inheritance with std::conditional

Why using std::conditional prevents a child struct to access public members of a parent struct? As a case in point, the following program doesn't compile, complaining that a is not defined. What would be the right way to fix this?

template <int i>
struct mtmd_A {
    static constexpr int a = i;
};

template <int i>
struct mtmd_B {
    static constexpr int a = i * i;
};

template <bool select>
struct mtmd: public std::conditional<select, mtmd_A<17>, mtmd_B<17>>::type {
    static constexpr int b = a;
};
int main()
{
    std::cout << mtmd<true>::b << std::endl;
}

Aucun commentaire:

Enregistrer un commentaire