Outputting Certain Attributes of a vector

I am currently unsure how i can output and display a certain attribute of a vector, like x. Please help i am totally new to vectors and i can't seem to find an example that i can relate to.



PointTwoD.h
1
2
3
4
5
6
7
8
9
10
11
class PointTwoD {
	private:
		int x,y;
		vector<int>vertices;
			
	public:
		void setX(int);
		void setY(int);
		vector<int> getX();
		vector<int>getY();
}



PointTwoD.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  #include "PointTwoD.h"

using namespace std;


void PointTwoD::setX(int coordX)
{
	x=coordX;
	vertices.push_back(x);
}
void PointTwoD::setY(int coordY)
{
	y=coordY;
	vertices.push_back(y);
}
vector<int> PointTwoD::getY()
{
	return vertices.y;
}
vector<int> PointTwoD::getX()
{
	return vertices.x;
}
Why are you getters for x and y returning vectors? x and y are ints. Getters for x and y should return ints.

If you want to return the vertices, then you should have a getter that does that:
1
2
3
vector<int> PointTwoD::getVertices () const
{  return vertices;
}


Lines 18,22: vectices is a vector of ints. A vector does not have x and y member variables.
Last edited on
Topic archived. No new replies allowed.