So I have an object called Vertex
which contains some parameters (let's call them sx
, sy
and i
). sx
, sy
and i
each have special setters: ie, Vertex
looks something like
class Vertex {
public:
float sx() { return sx; };
void setSx(float val) {
val > 0 ? sx = val : sx = 0;
};
float sy() { return sy; };
void setSy(float val) {
val >= 0 ? sx = val * 0.5 : sx = -val;
};
float i() { return i; };
void setI(float val) { i = val; };
private:
float sx, sy, i;
};
I would like to be able to iterate through a Vertex
's parameters without having to call each setter. For example:
Vertex* v = new Vertex();
for (int i = 0; i < Vertex::size; i++)
(*v)[i] = 0;
or something like that, instead of having to use the clunkier notation:
Vertex* v = new Vertex();
v->sx = 0;
v->sy = 0;
v->i = 0;
Is there any way to accomplish this in a more elegant way than just overloading operator[]
and using a switch
statement? I don't need to use the exact notation I demonstrated above, I just need a way to iterate through the components of a Vertex
without caring about the custom setters of each of them.