I have a struct for holding a 4D vector
struct {
float x;
float y;
float z;
float w;
} vector4f
And I\'m using a library th
If I had this situation, this is what I would do: C++ member variable aliases?
In your case it would look like this:
struct {
float& x() { return values[0]; }
float& y() { return values[1]; }
float& z() { return values[2]; }
float& w() { return values[3]; }
float operator [] (unsigned i) const { return this->values_[i]; }
float& operator [] (unsigned i) { return this->values_[i]; }
operator float*() const { return this->values_; }
private:
float[4] values_;
} vector4f;
However, this doesn't address the question of treating a struct as an array if that's specifically what you wanted to know about.