How to call a template super class's constructor from a template base class's constructor in c++?

后端 未结 1 1286
野性不改
野性不改 2021-01-28 21:23

I\'m programming in c++ using sublimetext3. My program has a superclass called Array, and a subclass called IntArray. Both classes are template classes. Currently, I\'m having t

相关标签:
1条回答
  • 2021-01-28 22:13

    Use

    template <class T> IntArray<T>::IntArray(T s) throw() : Array<T>(s) {}
                                                            //   ^^^ Use <T>
    

    More importantly, put the implemetation also in the .h file.

    See Why can templates only be implemented in the header file?.

    Other Issues I Noticed

    • It does not make sense that you are using T s for size. std::size_t s makes more sense.
    • It does not make sense that IntArray is a class template. It makes more sense to me to use:

      class IntArray : public Array<int> { ... };
      
    0 讨论(0)
提交回复
热议问题