CVector3 CVector3::CrossProduct(CVector3 v1, CVector3 v2)
{
CVector3 Normal;
// Calculate the cross product with the non communitive equation
Normal.x = ((v1.y * v2.z) - (v1.z * v2.y));
Normal.y = ((v1.z * v2.x) - (v1.x * v2.z));
Normal.z = ((v1.x * v2.y) - (v1.y * v2.x));
return Normal;
}
Vector code. namespace problem
I wasnt having this problem with my vector code until I put it inside of a namespace now the function below keeps giving this error:
line:71 Vector.cpp syntax error before `{' token
The vector class itself is in the namespace? You might need to put on the scope then, like
namespace::CVector3
[/source]
namespace::CVector3 CVector3::CrossProduct(namespace::CVector3 v1, namespace::CVector3 v2)
{
namespace::CVector3 Normal;
// Calculate the cross product with the non communitive equation
Normal.x = ((v1.y * v2.z) - (v1.z * v2.y));
Normal.y = ((v1.z * v2.x) - (v1.x * v2.z));
Normal.z = ((v1.x * v2.y) - (v1.y * v2.x));
return Normal;
}[/source]
namespace::CVector3
[/source]
namespace::CVector3 CVector3::CrossProduct(namespace::CVector3 v1, namespace::CVector3 v2)
{
namespace::CVector3 Normal;
// Calculate the cross product with the non communitive equation
Normal.x = ((v1.y * v2.z) - (v1.z * v2.y));
Normal.y = ((v1.z * v2.x) - (v1.x * v2.z));
Normal.z = ((v1.x * v2.y) - (v1.y * v2.x));
return Normal;
}[/source]
AP:Thanks but it didnt work
My files are like this:
header:
namspace Math
{
class CVector3 {...}
}
cpp file:
namspace Math
{
//function definitions
}
My files are like this:
header:
namspace Math
{
class CVector3 {...}
}
cpp file:
namspace Math
{
//function definitions
}
only the header files need to go in the namespace:
// Header File
namespace MyNamespace
{
class MyClass
{
// functions
};
}
// CPP File
MyClass::SomeFunction
{
}
// Header File
namespace MyNamespace
{
class MyClass
{
// functions
};
}
// CPP File
MyClass::SomeFunction
{
}
I tried it like PsyVision said but I got errors saying this:
syntax error before `::' token
So I it like this:
// Header File
namespace MyNamespace
{
class MyClass
{
// functions
};
}
// CPP File
Math::MyClass::SomeFunction
{
}
and I am back to the same error I had.
syntax error before `::' token
So I it like this:
// Header File
namespace MyNamespace
{
class MyClass
{
// functions
};
}
// CPP File
Math::MyClass::SomeFunction
{
}
and I am back to the same error I had.
here, a working example...
header file "vecMath.h"
CPP file
header file "vecMath.h"
namespace math{ class vector3 { public: float a,b,c; void copy(float a, float b, float c); };};
CPP file
#include "vecMath.h"using namespace math;void vector3::copy(float a, float b, float c){ // do copy}
First for a 3-vector you'll wont to have the functions inlined so you'll be better off defining them with-in the header instead.
Secondly your cross-product member function is alittle strange, because it will end-up like so:
CVector3 v, u, w;
CVector3 n = v.CrossProduct(u, w);
for a member function it should be the cross-product of the instance in question and another vector.
Thirdly you to won't pass your vectors by reference & constant reference instead of by value.
so with that in mind i would do something like this:
Secondly your cross-product member function is alittle strange, because it will end-up like so:
CVector3 v, u, w;
CVector3 n = v.CrossProduct(u, w);
for a member function it should be the cross-product of the instance in question and another vector.
Thirdly you to won't pass your vectors by reference & constant reference instead of by value.
so with that in mind i would do something like this:
#ifndef _VECTOR3_#defeine _VECTOR3_namespace math { template < typename T > struct vector3 { T x, y, z; //la-la-la vector3<T> cross(const vector3<T>&); //la-la-la }; template < typename T > inline vector3<T> vector3<T>::cross(const vector3<T>& u) { /* --- insert code --- */ }};#endif
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement