[C++] overloading [] on pointers
I have a vector and matrix class and i'm impementing an iterative method to solve a IBVP. In this class I have overloaded the [] to work on the class just fine.
However, now I have ran into a problem where I don't want to be passing around whole objects and copy them around I want to do it with pointers to the objects. However I still want to be able to use my array notation.
So currently I use syntax like the following:
Vector X(16);
Vector *X0=&X;
...
(*X0)[0]=.....
I'd like to be able to just use
X0[0]=....
So I tried adding a non-member function like the following
double& operator[] (Vector* V, unsigned i)
{
return (*V)[i];
}
however the compiler gives me an error saying [] must be a non static member.
I can't see how to overload this operator as a static member. Anyone have any suggestions?
|