问题向量在哪里找到c++ ??
当我编译时出现错误,我不明白问题出在哪里?
class Edge{
public:
int nid;
bool operator==(const Edge& edge) const {
return nid == edge.nid;
}
};
这里有
vector<Edge> edges;
vector<Edge>::iterator it;
it = find (edges.begin(), edges.end(), nid);
if( it != edges.end() )
edges.erase(it);
什么想法吗?!!!?
when i compile i has an error and i cannot understand where is the problem?
class Edge{
public:
int nid;
bool operator==(const Edge& edge) const {
return nid == edge.nid;
}
};
and problem here
vector<Edge> edges;
vector<Edge>::iterator it;
it = find (edges.begin(), edges.end(), nid);
if( it != edges.end() )
edges.erase(it);
any ideas ?!!!?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
find
会将向量中Edge
类型的对象与nid
进行比较(使用==
)。我猜nid
的类型是int
,除非您在Edge
之间实现operator==
,否则它将无法工作。和int
。您可以尝试:
find
will compare (with==
) the objects of typeEdge
in the vector withnid
. I guess thatnid
is of typeint
and that won't work unless you implementoperator==
betweenEdge
andint
.You can try :
您还没有描述问题的提取症状,但我猜想这与没有定义
operator!=
您可能也想将其定义为
如果您的 find(.. .,nid) 将 nid 作为整数参数,您可能还需要将 == 运算符重载为
You haven't described the extract symptoms of your problem, but I guess that it is related to that didn't define the
operator!=
You probably want to define it as
also if your find(...,nid) is taking nid as an integer argument, you probably also need to overload the == operator as
您也可以重载运算符!=,或者简单地否定 if 条件。
You can either overload the operator!=, too, or simply negate the if condition.
假设 nid 与类中的类型相同,我假设您收到有关 find() 第三个参数类型的投诉。我认为你可以将其切换为:
Assuming nid is the same type as in the class I assume you get a complaint about the type of the third argument to find(). I think you can switch it to: