Original Post
Hi!
I have a problem:
VECTOR3D Vector2 = vB - vA;
I would like this line to do this:
Vector2.x =vB.x - vA.x;
Vector2.y =vB.y - vA.y;
Vector2.z =vB.z - vA.z;
I saw in a code that a guy (DigiBen) used this:
struct VECTOR3D
{
public:
// A default constructor
VECTOR3D() {}
VECTOR3D(float X, float Y, float Z)
{
x = X; y = Y; z = Z;
}
// Here we overload the + operator so we can add vectors together
VECTOR3D operator+(VECTOR3D vVector)
{
// Return the added vectors result.
return VECTOR3D(vVector.x + x, vVector.y + y, vVector.z + z);
}
// Here we overload the - operator so we can subtract vectors
VECTOR3D operator-(VECTOR3D vVector)
{
// Return the subtracted vectors result
return VECTOR3D(x - vVector.x, y - vVector.y, z - vVector.z);
}
(....)
float x, y, z;
}
Shall I always add a constructor?? If i do this in my code, i get a lot of errors from VC++. It asks for a constructor for each structure..
Can someone explain me??
Thanks a lot