Im having an issue where i cannot manage to print the set of coords which are held within list 'vertex' vertices.. To explain, 'Vertex' is a class which basically holds two coordinates that make a vertex (where two lines of a shape meet). The issue is within the second for loop that is meant to print out the coordinates held within the list.. Can anyone help me in trying to get this printed out ? ive tried numerous ways and errors have always given me a problem so far.. Code is below, Thanks for the help!
INT MAIN
int main(){
//obj
Console con;
RandomNumber rand;
Vertex vertex;
//Declarations
list<Vertex>vertices;
//list<Vertex>::iterator ii;
//set Vertex coords and push into list
for (int i = 0; i <= 8; i++){
vertices.push_back(Vertex(rand.random(0, 10), rand.random(0, 10)));
}
//iterate through the list outputting a char at each vertex (coords)
for (list<Vertex>::iterator ii = vertices.begin(); ii != vertices.end(); ii++){
cout << vertices[ii];
}
system("pause");
}
VERTEX CLASS
#pragma once
class Vertex
{
int x;
int y;
public:
Vertex(int x = 10, int y = 10);
~Vertex();
int getX() const;
int getY() const;
void setX(unsigned x);
void setY(unsigned y);
bool operator== (const Vertex &p2) const;
};
#include "Vertex.h"
Vertex::Vertex(int x, int y)
{
this->x = x;
this->y = y;
}
Vertex::~Vertex(){}
int Vertex::getX() const {
return x;
}
int Vertex::getY() const {
return y;
}
void Vertex::setX(unsigned x) {
this->x = x;
}
void Vertex::setY(unsigned y) {
this->y = y;
}
bool Vertex::operator== (const Vertex &point) const {
return (this->x == point.getX()) && (this->y == point.getY());
}