I have a class that can inherit from an empty struct or from a struct with some members, depending on a bool
. Using that same bool
, I am adding an if constexpr
block to access the members of the base class, but I am getting a compiler error
struct A{};
struct B{};
struct C{};
template <typename J0, typename J1>
struct HasFriction {
constexpr static bool value = false;
};
template <> struct HasFriction<A,B> {
constexpr static bool value = true;
};
template <bool> struct Friction { };
template <> struct Friction<true> { int value = 4; };
template <typename J0, typename J1>
struct MyStruct : public Friction<HasFriction<J0, J1>::value> {};
int main()
{
if constexpr (HasFriction<A, C>::value) {
MyStruct<A,C> f;
return f.value;
} else {
MyStruct<A,C> no_f;
return 0;
}
}
Why is this not working, and how should I fix it?