I have a PolygonList and a Polygon type, which are std::lists of Points or lists of lists of points.
class Point {
public:
int x, y;
Point(int x1, int y1)
{
x = x1;
y = y1;
}
};
typedef std::list<Point> Polygon;
typedef std::list<Polygon> PolygonList;
// List of all our polygons
PolygonList polygonList;
However, I'm confused on reference variables and pointers.
For example, I would like to be able to reference the first Polygon in my polygonList, and push a new Point to it.
So I attempted to set the front of the polygonList to a Polygon called currentPolygon like so:
Polygon currentPolygon = polygonList.front();
currentPolygon.push_front(somePoint);
and now, I can add points to currentPolygon, but these changes end up not being reflected in that same polygon in the polygonList. Is currentPolygon simply a copy of the Polygon in the front of polygonList? When I later iterate over polygonList all the points I've added to currentPolygon aren't shown.
It works if I do this:
polygonList.front().push_front(somePoint);
Why aren't these the same and how can I create a reference to the physical front polygon rather than a copy of it?