我想在类中编写一个函数,使用我之前在该类中定义的运算符。但我不知道如何向运算符显示现在您必须使用 YOUR (x, y)。
(我看到有人在php中使用了$this->func_name
,但是这里我不知道。
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))
//...
}
最佳答案
你在哪里有 /* what ?? */
你想要 *this
关于c++ - 我们如何在该类中使用运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9040303/