【发布时间】:2016-12-16 06:38:26
【问题描述】:
我想遍历对象列表的列表,
list<list<Point>> gnuPoints;
这是一个静态列表,它接受来自各种类(如圆形和多边形)的列表,所有这些类都将多个对象(即 Point(x,y))推送到列表中
while (angle != 360)
{
double x = m_radius*cos(angle);
double y = m_radius*sin(angle);
angle += 30;
circlePoint.push_back(Point(x, y));
}
similarly goes with Polygon and line shapes
polygonPoint.push_back(Point(x,y));
linePoint.Push_back(point(x,y));
然后将这些列表推送到 gnuPoint(list >)。
gnuPoints.push_back(circlePoints);
gnuPoints.push_back(polygonPoints);
gnuPoints.push_back(linePoints);
现在我想将所有这些不同形状的 x,y 值写入一个文件, 要迭代它,我在这段代码之后找不到任何特定的解决方案。
for (list<list<Point>>::iterator it = Point::gnuPoints.begin();
it != Point::gnuPoints.end();
it++)
{
//My assumption is that another For loop would come but could not apply
as I don't know what is available at the first index of gnuPoints list.
}
【问题讨论】:
-
for (auto inner_list : gnuPoints) { for (auto element : inner_list) { ... } }? -
至于'我不知道gnuPoints的第一个索引有什么可用':是的,你知道;这是
list<Point>。 -
是的,它是一个列表
,但我不知道它是 CirclePoint 还是 LinePoint,因为这些列表是在运行时推送的,并且顺序不具体。 -
两者都不是。这只是一个
list<Point>。届时任何其他信息都会丢失。如果您需要区分内部列表,也许地图会更好。 -
谢谢它的帮助,是的,但也想知道使用对象地图列表。