1

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;
}

Edit This doesn't seem to be a duplicate of this question since the problem appears only when I add std::conditional.

MTMD
  • 1,162
  • 2
  • 11
  • 23

0 Answers0