I use a vector class that has always base = 0 (uBLAS vector). I want
my own vector class (say my_vector) with a base that can be different
from zero.

//HPP
template<class T>
my_vector<T> : public vector<T>
{
my_vector(size_type size, size_type base) : vector<T>(size), v_start
(base) {};
size_type startIndex;
T& operator [] (size_type index);
const T& operator [] (size_type index) const;
}

//CPP
template <class T>
T& my_vector<T>::operator [] (size_type index) {
    return vector<T>::operator[](index - this->v_start);
};

template <class T>
const T& my_vector<T>::operator [] (size_type index) const {
    return vector<T>::operator[](index - this->v_start);
};

The problem: I would like to use every operator overloading defined
for vector.

I thought that I would need a constructor for my_vector that receives
a vector. But (please tell me if I wrong) now I believe that what I
need is to overwirte the operator "=" in this way:

template <class T>
my_vector<T>& my_vector<T>::operator = (const vector<T>& source) {
      if (this==&source) return *this;
      size_type temp = this->v_start;
      vector<T>::operator =  (source);
      this->v_start = temp;
      return *this;
};

In this case if I write:

my_vector<double> a(3, 1); //size-base constructor: size 3, base 1
vector<double> b(2);
a = b +  b;

a should have has startIndex = 1.

Is this right? Is this the standard way to solve my problem? If the
operator "=" is not overwritten, the copy constructor is called? or
the vector<T>::= is called?

thanks

Stefano





To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.


Yahoo! Groups Sponsor
ADVERTISEMENT
click here
Web Bug from http://us.adserver.yahoo.com/l?M=315388.5526708.6599542.3001176/D=groups/S=:HM/A=2372354/rand=956025845


Yahoo! Groups Links

Reply via email to