我有一个类可以用作某些基元或自定义类型的包装器。我想为自定义模板类型编写显式专业化。我的代码重现了该问题:
template < class T >
struct A {
void func() { std::cout << "base\n"; }
};
template <>
struct A<int> {};
template < class T, class CRTP >
struct BaseCrtp {
void someFunc() {
CRTP::someStaticFunc();
}
};
struct DerrType : BaseCrtp<int, DerrType> {
static void someStaticFunc() {}
};
template < class T, class CRTP >
struct A< BaseCrtp<T, CRTP> > {
void func() { std::cout << "sometype\n"; }
};
int main() {
A<DerrType> a;
a.func(); // print: "base". should …Run Code Online (Sandbox Code Playgroud) c++ templates partial-specialization template-specialization c++20