Overloading [] operator

Hi everyone.I am trying to overload operator [].This is the following problem.
In class Vector.h i have
1
2
3
4
5
  class{
private:Point *vector;
int dim;//for dimension
//I did not write all functions and constructors only code for the question
};

In point.h under public i have define operator[] like this
int& operator[](int i);.Now in Point.cpp(i have included point.h) i have
1
2
3
4
5
6
7
8
9
10
//only code for the question
int& Point::operator[](const int index)
{

	return vector[index];//says vector is not defined
//I was thinking i could get vector from class vector because array vector
//has it's elements from class Point

}

What is the problem here?
vector[index] is a Point but the return type is int&.
Thank you.
I have change int& to Point& but it says vector[index] :vector undefined
Last edited on
You haven't given the class a name. operator[] should be part of Vector, not Point, isn't that so?
Last edited on
Yes,I see it now.Thank you very much for your help, I appreciate it.
Topic archived. No new replies allowed.