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 | |
|
|
Yahoo! Groups Links
- To visit your group on the web, go to:
http://groups.yahoo.com/group/c-prog/
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
