0

I have a two levels template:

types

class Type{};
class TypeExt:public Type{};

1, Fist level:

//the type must be an inheritance of Type
template<typename T, typename std::enable_if<std::is_base_of<Type, T>::value>::type* = nullptr>
class FirstLevel{};

class FirstLevelSpecialization_1:public FirstLevel<Type>{};
class FirstLevelSpecialization_2:public FirstLevel<TypeExt>{};

2, Second Level

//the type must be an inheritance of FirstLevel
template<typename T, typename std::enable_if<std::is_base_of<FirstLevel, T>::value>::type* = nullptr>
class SecondLevel{};

class SecondLevelSpecialization: public SecondLevel<FirstLevelSpecialization_1>{};

The last line will give an error:

Invalid template arguments

I know how to solve this problem in Java,questions are:

1,Is this problem solvable in C++?
2,If yes,would you please give some tips to solve it?
Alex Luya
  • 9,412
  • 15
  • 59
  • 91
  • Sound like [this](https://stackoverflow.com/questions/17390605/doing-a-static-assert-that-a-template-type-is-another-template) is what you want. – NathanOliver Apr 21 '23 at 03:29
  • Or [this](https://stackoverflow.com/questions/25845536/trait-to-check-if-some-specialization-of-template-class-is-base-class-of-specifi). – joergbrech Apr 21 '23 at 08:39

0 Answers0