小编Dmi*_*bev的帖子

针对未来派生类型的基本模板类型的模板专门化

我有一个类可以用作某些基元或自定义类型的包装器。我想为自定义模板类型编写显式专业化。我的代码重现了该问题:


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

3
推荐指数
1
解决办法
137
查看次数