Set up a list to store pointers to a “Points” class…

list<Point*> m_pointList;

Add to the list…

Point* p = new Point(x, y);
m_pointList.push_back(p);

Then iterate the list using this…

std::list<Point*>::iterator it = m_pointList.begin();
while (it != m_pointList.end())
{
    Point* p = *it;

    // do something with the Point here!

    it++;
}

…or, if you’d prefer a for loop…

for(std::list<Point*>::iterator it = m_pointList.begin(); it != m_pointList.end(); ++it)
{
    Point* p = *it;
    // do something with the Point here!
}


Discover more from

Subscribe to get the latest posts sent to your email.

Leave a comment

Trending