making a Simple Math Library

i have to make a Simple Math Library with a Vector class, Matrix class and a node class i have all the info i need to do it, but i have 3 errors and i need some help here is the code i have sofar

#include <iostream>
#include <math.h>

float x;
float y;
float length;
float lengthSquared;

class Vector2
{
public:

Vector2::Vector2(float xValue, float yValue)
{
xValue = x;
yValue = y;
}

Vector2::~Vector2()
{
}

float GetMagnitude()
{
length = sqrt( ( x*x ) + ( y*y ) );
}

float GetMagnitudeSquared()
{
lengthSquared = x*x + y*y;
}

void Normalise()
{
length = GetMagnitude();
normal.x = x / length;
normal.y = y / length;
}

};


and here are the errors

error C2065: 'normal' : undeclared identifier
error C2228: left of '.x' must have class/struct/union
error C2228: left of '.y' must have class/struct/union


its got to be something simply im not seeing
You never declare normal in your Normalise() function.
i declare normal in the Normalise() function

but i still have

error C2228: left of '.x' must have class/struct/union
error C2228: left of '.y' must have class/struct/union
show us the code
your 'x', 'y', 'length' and 'lengthSquared' are not members of Vector2.
move lines 5 - 7 inside the 'class Vector2{'
ok looks like this now

#include <iostream>
#include <math.h>



class Vector2
{
float x;
float y;
float length;
float lengthSquared;
public:

Vector2::Vector2(float xValue, float yValue)
{
xValue = x;
yValue = y;
}

Vector2::~Vector2()
{
}

float GetMagnitude()
{
length = sqrt( ( x*x ) + ( y*y ) );
}

float GetMagnitudeSquared()
{
lengthSquared = x*x + y*y;
}

void Normalise(float normal)
{
length = GetMagnitude();
normal.x = x / length;
normal.y = y / length;
}

};
Last edited on
Topic archived. No new replies allowed.