I made a 3d vector class like this
struct Vector3D {
float x;
float y;
float z;
Vector3D() {
x = 0;
y = 0;
z = 0;
}
Vector3D(float x1,float y1,float z1=0) {
x = x1;
y = y1;
z = z1;
}
//member functions for operator overloading, dot product, etc.
};
But now I want to make a child class specific to Euler angles. So far I have
struct Euler3D : Vector3D {
float roll;
float pitch;
float yaw;
};
How do I make the class so that roll pitch and yaw reference the same data as x, y and z? I think it involves union or something.
I want to be able to achieve something like this:
Euler3D a = {1, 2, 3};
cout << a.x << endl; // prints 1
a.x = 1.5;
cout << a.roll << endl; //prints 1.5
Thank you
Euler3Dinherent fromVector3Dat all if they are completely unrelated? If you really need to have them share memory, you could create a separate union with members ofEuler3DandVector3D.rollidentifier it will be replaced withx. i.e.int x = myVector.x; int roll = myEuler.roll; // Error because you've defined int x twice!Euler3Da separate class with converting constructors and operators.