How to call constructor of a template base class in a template derived class?

后端 未结 1 2021
北恋
北恋 2021-02-06 02:53

Let\'s say I have a base template class Array:

template  class Array{
    protected:
        T* m_data;
        int size;
    public:
             


        
相关标签:
1条回答
  • 2021-02-06 03:50

    Combine your solutions, use the initializer list and the full name:

    NumericArray<T>::NumericArray(int n)
     : Array<T>(n)
    {
    
    }
    

    Also, since they become a dependent name, fields of Array have to be accessed like this:

    Array<T>::m_data; // inside a NumericArray method
    

    Also, if it's not some experiment or homework, please use std::vector instead of pointer and size.

    0 讨论(0)
提交回复
热议问题