Overloading square brackets while inheriting vector class in c++? -


i want inherit class called arithmeticvector stl vector class. problem square brackets overaloading. here code:

    template<class type> type& arithmeticvector<type>::operator[](int index) const{      if(this->size()<=index || index < 0){          throw string("size error!");      }else{          return vector<type>::operator[](index);      }  } 

it gives error:

binding of reference type int value of type const int drops qualifiers.

in line:

        return vector<type>::operator[](index); 

how can fix it?

you should either drop const or add const:

template <class type> const type& arithmeticvector<type>::operator[](int index) const  template <class type> type& arithmeticvector<type>::operator[](int index) 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Socket.connect doesn't throw exception in Android -

iphone - How do I keep MDScrollView from truncating my row headers and making my cells look bad? -