This question is my mistake. The code described below is being built well with no problem.
I have this class.
Vector.h
struct Vector
{
union
{
float elements[4];
struct
{
float x;
float y;
float z;
float w;
};
};
float length();
}
Vector.cpp
float Vector::length()
{
return x; // error: 'x' was not declared in this scope
}
How to access the member x,y,z,w?
You need an instance of your struct inside the anonymous union. I don't know exactly what you want to achive, but e.g. something like this would work: