ok i have this class:
Vector.h:
#ifndef VECTOR_H
#define VECTOR_H
#include <math.h>
namespace NMath
{
class CVector3
{
public:
CVector3( float x = 0.0f, float y = 0.0f, float z = 0.0f )
{
_x = x;
_y = y;
_z = z;
}
CVector3 operator+=( const CVector3 &vector )
{
return *this = ( *this + vector );
}
CVector3 operator+( const CVector3 &vector )
{
return CVector3( vector._x + _x, vector._y + _y, vector._z + _z );
}
CVector3 operator-=( const CVector3 &vector )
{
return *this = ( *this - vector );
}
CVector3 operator-( const CVector3 &vector )
{
return CVector3( _x - vector._x, _y - vector._y, _z - vector._z );
}
CVector3 operator*=( float number )
{
return *this = ( *this * number );
}
CVector3 operator*( float number )
{
return CVector3( _x * number, _y * number, _z * number );
}
CVector3 operator/=( float number )
{
return *this = ( *this / number );
}
CVector3 operator/( float number )
{
return CVector3( _x / number, _y / number, _z / number );
}
CVector3 operator-()
{
return CVector3( -_x, -_y, -_z );
}
float Dot( CVector3 &vector )
{
return CVector3( _x * vector._x, + _y * vector._y, + _z * vector._z );
}
CVector3 operator*( CVector3 &vector )
{
return CVector3( _y * vector._z - _z * vector._y, _z * vector._x - _x * vector._z, _x * vector._y - _y * vector._x, );
}
float Lenght()
{
return sqrt( _x * _x, _y * _y, _z * _z );
}
bool operator!=( const CVector3 &vector )
{
return ( vector._x == _x, vector._y == _y, vector._z == _z );
}
bool operator==(const CVector3 &vector )
{
return ( vector._x != _x, vector._y != _y, vector._z != _z );
}
CVector3 Normalize()
{
float lenght = Lenght();
x /= lenght;
y /= lenght;
z /= lenght;
return *this;
}
float Distance( CVector3 &vector )
{
float distance_x = vector._x - _x;
float distance_y = vector._y - _y;
float distance_z = vector._z - _z;
return sqrt( distance_x * distance_x, distance_y * distance_y, distance_z * distance_z );
}
float _x;
float _y;
float _z;
};
}
#endif
and this is my main.cpp:
#include "Vector.h"
#include <iostream>
void PrintV( NMath::CVector3 &v );
void main()
{
NMath::CVector3 *a = new NMath::CVector3( 1, 2, 3 );
NMath::CVector3 *b = new NMath::CVector3( 3, 8, 4 );
NMath::CVector3 *c = new NMath::CVector3( 3, 4, 5 );
NMath::CVector3 *d = new NMath::CVector3( 3, 2, 1 );
PrintV( a + b );
PrintV( b - a );
PrintV( b / a );
PrintV( a * 5 );
getch();
delete a, b, c, d;
}
void PrintV( NMath::CVector3 &v )
{
std::cout << v._x << " " << v._y << " " << v._z std::endl;
}
now for a reason i don't know i am getting these errors:
------ Build started: Project: vectortest, Configuration: Debug Win32 ------
Compiling...
main.cpp
c:\Documents and Settings\ryan\My Documents\Visual Studio Projects\vectortest\main.cpp(5) : error C2653: 'NMath' : is not a class or namespace name
c:\Documents and Settings\ryan\My Documents\Visual Studio Projects\vectortest\main.cpp(5) : error C2065: 'CVector3' : undeclared identifier
c:\Documents and Settings\ryan\My Documents\Visual Studio Projects\vectortest\main.cpp(5) : error C2065: 'v' : undeclared identifier
c:\Documents and Settings\ryan\My Documents\Visual Studio Projects\vectortest\main.cpp(5) : error C2182: 'PrintV' : illegal use of type 'void'
c:\Documents and Settings\ryan\My Documents\Visual Studio Projects\vectortest\main.cpp(5) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Build log was saved at "file://c:\Documents and Settings\ryan\My Documents\Visual Studio Projects\vectortest\Debug\BuildLog.htm"
vectortest - 5 error(s), 0 warning(s)
---------------------- Done ----------------------
Build: 0 succeeded, 1 failed, 0 skipped
I have been working on a bood size OpenGL project and been using classes and namespace just like this but for some reason this on is not working, anyone now why?