gpt4 book ai didi

c++ - 我们如何在该类中使用运算符?

转载 作者:太空宇宙 更新时间:2023-11-03 10:33:39 25 4
gpt4 key购买 nike

我想在类中编写一个函数,使用我之前在该类中定义的运算符。但我不知道如何向运算符显示现在您必须使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com