我有代码:
class Base {};
template <T>
void Print(const T& obj);
我想专门针对
Print
派生自 Base
的所有类。
我尝试了
concept
:
template <class T>
concept DerivedFromBase = std::is_base_of_v<Base, T>;
template <DerivedFromBase T>
void Print<T>(…) { … }
但是编译器说它是部分专业化 - 而函数不能拥有它。
还有哪些其他解决方案和途径?
只需删除
<T>
就足够了:
template <class T>
concept DerivedFromBase = std::is_base_of_v<Base, T>;
template <DerivedFromBase T>
void Print(…) { … }