MSVC++ compiler error C2143

前端 未结 3 804
孤独总比滥情好
孤独总比滥情好 2021-01-25 12:45

The following code excerpt is responsible for a cryptic MSVC++ compiler error:

template class Vec : public vector{
  public:
    Vec() :          


        
3条回答
  •  我在风中等你
    2021-01-25 13:09

    Try

    template class Vec : public vector{
      public:
        Vec() : vector(){} // no 
        Vec(int s) : vector(s){} // same
    
        T& operator[](int i){return at(i);  }
        const T& operator[](int i)const{ return at(i);}
    };
    

    The constructor for a template class does not include the template signature in its name.

    As a side note, your second constructor should really be

    Vec(typename vector::size_type s) : vector(s){} // not necessarily int
    

    Finally, you really shouldn't derive from vector, as it has a non-virtual destructor. Do not attempt to delete a Vec through a pointer to a vector.

提交回复
热议问题