I have the code:
class Base {};
template <T>
void Print(const T& obj);
I want to specialize Print
for all classes that are derived from Base
.
I tried the concept
:
template <class T>
concept DerivedFromBase = std::is_base_of_v<Base, T>;
template <DerivedFromBase T>
void Print<T>(…) { … }
But compiler says that it’s partial specialization – and functions can’t have it.
What are the other solutions and approaches?
It is enough to simply remove the <T>
:
template <class T>
concept DerivedFromBase = std::is_base_of_v<Base, T>;
template <DerivedFromBase T>
void Print(…) { … }