https://blog.csdn.net/m0_53421868/article/details/121188326

https://blog.csdn.net/lucust/article/details/127144157

类模板与继承

  • In template: field has incomplete type 'Son'
    class Son : public Parent<Son> {
    public:
    Son() {
        a = 50;
        printf("I'm Son,a =%d \n", a);
    }
    };

    如果在Parent里声明一个模板类型的字段就会报错,如果只是方法参数引用或者泛型参数引用则不会有问题。

类模板定义静态成员

https://blog.csdn.net/danshiming/article/details/131975048

// ==== ca.h =====
template<class T>
class ca
{

public:

    static std::vector<T> m_vec;    

};

// 在类外必须声明m_vec,否则会报链接错误
template<class T>
std::vector<T> ca<T>::m_vec;

注意事项

1.泛型类中好像不能定义虚方法


0 条评论

发表回复

您的电子邮箱地址不会被公开。