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 -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -