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

后端 未结 1 2022
北恋
北恋 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::NumericArray(int n)
     : Array(n)
    {
    
    }
    

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

    Array::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)
提交回复
热议问题