|
From: Nicolas W. <nic...@gm...> - 2001-06-02 15:10:07
|
Hi!
There seems to be a problem with the stl list iterator...I'm writing a small
polygon(2d) editor. I wrote the two classes Vector2d and Polygon2d and
Poly2d has operator[] overloaded, it returns a Vector2d reference. Vector2d has
the methods getX() and getY(). PolyIterator is typedef'd as
list<Polygon2d>::iterator. Now I have the following piece of code:
//m_polyList is list<Polygon2d>
PolyIterator listEnd = m_polyList.end();
PolyIterator e;
for(e = m_polyList.begin(); e != listEnd; ++e)
{
int vertexCount = e->getVertexCount();
if(vertexCount <= 0)
continue;
//draw poly
MoveToEx(hDc, (int)(*e)[0].getX(), (int)(*e)[0].getY(), NULL);
for(int i = 1; i < vertexCount; ++i)
{
LineTo(hDc, (int)(*e)[i].getX(), (int)(*e)[i].getY());
}
LineTo(hDc, (int)(*e)[0].getX(), (int)(*e)[0].getY());
} //end for
This does not work as expected (e is a Polygon2d iterator, so *e is a
Polygon2d and (*e)[0].getX() should call operator[] on the Poly and getX() on the
returned Vector2d). It compiles, but the output looks very strange...it does
work, however, if I save *e in a Polygon2d reference and use that, like so:
for(e = m_polyList.begin(); e != listEnd; ++e)
{
int vertexCount = e->getVertexCount();
Polygon2d& poly = *e;
if(vertexCount <= 0)
continue;
//draw poly
MoveToEx(hDc, (int)poly[0].getX(), (int)poly[0].getY(), NULL);
for(int i = 1; i < vertexCount; ++i)
{
LineTo(hDc, (int)poly[i].getX(), (int)poly[i].getY());
}
LineTo(hDc, (int)poly[0].getX(), (int)poly[0].getY());
} //end for
Any ideas why this is the case?
TIA,
Nico
--
Machen Sie Ihr Hobby zu Geld bei unserem Partner 1&1!
http://profiseller.de/info/index.php3?ac=OM.PS.PS003K00596T0409a
--
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net
|