-1
我有一个Points列表。访问C++中的列表元素函数
class Point {
private:
int xval, yval;
public:
Point(int x=0, int y=0) {
xval = x;
yval = y;
}
int x() { return xval; }
int y() { return yval; }
friend bool operator== (const Point a,const Point b) {
return (a.xval==b.xval && a.yval==b.yval);
}
};
现在主要想寻找某些点,如果他们在一个列表中存在,如果是这样,我想访问点的y值。
list<Point> coordinates;
for (list<Point>::iterator i = coordinates.begin(); i!=coordinates.end(); i++) {
if(*i.y()>height) height = *i.y();
}
现在我的问题是如何访问一个点的y()函数?因为这段代码给我一个错误,告诉我,y是不是元素 '的std :: _ List_iterator < _Mylist>'
如果(我 - > y()> height)height = i-> y(); – malat