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
Post a Comment