I was following template class restriction, but ran into errors in gcc:
error: multiple types in one declaration
error: declaration does not declare anything
It compiles if I remove the enable_if block. Can anybody explain if I am missing something?
template<class A, class B, class C, class D>
typename std::enable_if<
std::is_base_of<baseofA, A>::value &&
std::is_base_of<baseofB, B>::value &&
std::is_base_of<baseofC, C>::value &&
std::is_base_of<baseofD, D>::value>::type
class library {
//whatever
};
You’re not using
enable_ifcorrectly.static_assertwould be more appropriate in this case.If you want to use
enable_ifinstead you must create a dummy template parameter that depends on the enabled type for it to work as you desire.But IMO, the
static_assertmethod is better because you can provide a descriptive error message instead of the compiler complaining about failing to find a type namedtypein the latter case.