I want to write a function in class, using the operator that I’ve defined it later before in that class.But I don’t know how to show the operator that now you must use the values of YOUR (x,y).
(I saw someone used $this->func_name in php. but here I don’t know.
class Point
{
public:
int x;
int y;
bool operator==(Point p)
{
if (x == p.x && y == p.y)
return 1;
return 0;
}
bool searchArea(vector <Point> v)
{
for (int i = 0; i < v.size(); i++)
if (v[i] == /* what ?? */ )
return 1;
return 0;
}
};
int main()
{
//...
.
.
.
if (p.searchArea(v))
//...
}
I’ve seen two ways:
thisis a pointer to the current object.*thisis a reference to the current object. Since the comparison operator takes a reference, you have to dereference thethispointer. Or you can just call the member function directly, which passesthisimplicitly.