迭代对象列表
Iterating over list of list of object
我想迭代对象列表
list<list<Point>> gnuPoints;
这是一个静态列表,它接受来自Circle和Polygon等各个类的列表,所有类别将多个对象(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&lt; list&lt; point>>)。
gnuPoints.push_back(circlePoints);
gnuPoints.push_back(polygonPoints);
gnuPoints.push_back(linePoints);
现在我想在文件中写下所有这些不同形状的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 (list<list<Point>>::iterator it = Point::gnuPoints.begin();
it != Point::gnuPoints.end();
it++)
{
for (list<Point>::iterator innerIt = it->begin(); innerIt != it->end(); ++innerIt)
}
如果您已经在支持C 11的编译器上,则可以简单地写为:
for (const auto& container : Point::gnuPoints)
{
for (const auto& item : container)
{
}
}
相关文章:
- C++ 创建包含链表和字符串的对象的链接列表时出错
- 我使用向量来创建类对象列表.初始化向量时如何使用参数调用构造函数?
- 从封装在对象中的函数 C++ 返回时为空的列表
- 如何在不销毁对象的情况下返回对象列表
- 如何使用Q_PROPERTY公开自定义对象列表
- 链接列表在 cpp 中包含不同的对象类
- 如何使用对象制作分数列表并获得平均值
- 什么更好?返回对象指针列表?或返回指向对象列表的指针?
- 如何将成员函数作为参数传递并在派生对象上执行方法列表
- 我可以从列表中获取对象并复制它们,但如何删除我复制的对象?
- 如何获取列表的每个对象并调用getName方法来打印其名称
- 如何在Windows Media Foundation SDK中指定语言列表对象
- 在 DLL 中嵌入 Python:Py_DECREF列表对象时访问冲突读取位置
- 将类的每个实例添加到列表对象的构造函数
- 列表<对象*>迭代器中的分段错误
- 如何使用list::sort()对STL列表对象进行排序,同时将自定义排序函数作为参数传递给list::排序
- 如何防止客户端修改列表对象
- c++列表对象错误
- 在列表对象中使用对象的派生函数
- 编译器错误 使用列表<对象*的迭代器> C++