I'm working with 3D vectors for 3d Graphics. I created a class vec3 to add functions like getX, getY, getZ, setX, setY, setZ, setXYZ... and so on.
#include <armadillo>
using namespace arma;
// An extension to VEC class for Armadillo for 3D graphics.
class vec3 : public vec
{
public:
// Constructor inits vector to 0,0,0
vec3() : vec(3,fill::zeros) {}
~vec3(void){};
double getX() const { return at(0); }
double getY() const { return at(1); }
double getZ() const { return at(2); }
void setX(double x){ ?????? = x; }
};
I found myself lost in a very unusual situation i never found:
How do i use (i) access to elements... inside the class?
For the getter function, as you can see, it is easy since we have an "at" function, at least. But how do i create a setX function, that inserts in the 0 position of the vector the given element...
I tried this(i) , obviously didn't work. I feel so newbie here... Where is "vec" built over?. A std::vector?... Am i doing right by doing this simple stuff?
at(0) = x;
should work if vec is derived from std::vector because at function can return non-constant reference.