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

后端 未结 1 1307
野性不改
野性不改 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  IntArray::IntArray(T s) throw() : Array(s) {}
                                                            //   ^^^ Use 
    

    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 { ... };
      

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