Original Post
I'm trying to design a vector class for my app. In testing it, whenever I try to do the line myvector3 = myvector plus myvector2 in the app I get this error: Error: Math error LNK2019: unresolved external symbol "public: __thiscall ShyrVec4::ShyrVec4(float,float,float,float)" (??0ShyrVec4@@QAE@MMMM@Z) referenced in function "public: class ShyrVec4 __thiscall ShyrVec4::operator+(class ShyrVec4 const &)const " (??HShyrVec4@@QBE?AV0@ABV0@@Z) Now, here's the full code for my header. however, I think that the plus operator is the problem. I've been having some weird issues with the plus symbol being eaten in this bbs, so if you can't see the symbol I'll try and repost it. (it's the third operator defined, btw) And, of course, here's the simple main function I'm using to test the class: I haven't done a lot of operator overloading in the past, so I think I may have done something wrong. Any help is really appreciated! cheers!
[source lange="cpp]
#include <math.h>
class ShyrVec4
{
public:
float x, y, z, w;
ShyrVec4() {};
ShyrVec4(const float x, const float y, const float z, const float w);
void Set(const float x, const float y, const float z);
ShyrVec4 Cross( const ShyrVec4 &a ) const;
ShyrVec4 ⨯( const ShyrVec4 &a, const ShyrVec4 &b );
float Length(const float x, const float y, const float z);
void Zero();
float operator[]( const int index ) const;
float &operator[]( const int index );
ShyrVec4 &operator =(const ShyrVec4 &a);
ShyrVec4 operator +(const ShyrVec4 &a) const;
ShyrVec4 operator -(const ShyrVec4 &a);
ShyrVec4 &operator +=(const ShyrVec4 &a);
ShyrVec4 &operator -=(const ShyrVec4 &a);
ShyrVec4 &operator *=(const ShyrVec4 &a);
//int operator ==(const ShyrVec4 &a);
//int operator !=(const ShyrVec4 &a);
//Dot Product
float operator *(const ShyrVec4 &a);
//Scalar Multiplication
ShyrVec4 operator *(const float a);
};
inline float ShyrVec4::operator[]( const int index ) const {
return ( &x )[ index ];
}
inline float &ShyrVec4::operator[]( const int index ) {
return ( &x )[ index ];
}
inline ShyrVec4 ShyrVec4::operator +(const ShyrVec4 &a) const
{
return ShyrVec4(x + a.x, y + a.y, z + a.z, 1);
}
inline ShyrVec4 ShyrVec4::operator -(const ShyrVec4 &a)
{
return ShyrVec4(x - a.x, y - a.y, z - a.z, 1);
}
inline ShyrVec4 &ShyrVec4::operator -=(const ShyrVec4 &a)
{
x -= a.x;
y -= a.y;
z -= a.z;
return *this;
}
inline ShyrVec4 &ShyrVec4::operator +=(const ShyrVec4 &a)
{
x += a.x;
y += a.y;
z += a.z;
return *this;
}
inline ShyrVec4 &ShyrVec4::operator *=(const ShyrVec4 &a)
{
x *= a.x;
y *= a.y;
z *= a.z;
return *this;
}
inline float ShyrVec4::operator *(const ShyrVec4 &a)
{
return x *a.x + y * a.y + z * a.z;
}
inline ShyrVec4 ShyrVec4::operator *(float a)
{
return ShyrVec4(x * a, y * a, z * a, 1);
}
inline ShyrVec4 &ShyrVec4::operator =(const ShyrVec4 &a)
{
x = a.x;
y = a.y;
z = a.z;
return *this;
}
inline float ShyrVec4::Length(const float x, const float y, const float z)
{
float temp;
temp = x*x + y*y + z*z;
return sqrt(temp);
}
inline void ShyrVec4::Zero()
{
this->x = 0;
this->y = 0;
this->z = 0;
}
inline void ShyrVec4::Set(const float x, const float y, const float z)
{
this->x = x;
this->y = y;
this->z = z;
this->w = 1;
}
inline ShyrVec4 ShyrVec4::Cross( const ShyrVec4 &a ) const {
return ShyrVec4( y * a.z - z * a.y, z * a.x - x * a.z, x * a.y - y * a.x, 1 );
}
inline ShyrVec4 &ShyrVec4::Cross( const ShyrVec4 &a, const ShyrVec4 &b ) {
x = a.y * b.z - a.z * b.y;
y = a.z * b.x - a.x * b.z;
z = a.x * b.y - a.y * b.x;
return *this;
}
[source lang="cpp]
int main ()
{
ShyrVec4 myvector;
ShyrVec4 myvector2;
ShyrVec4 myvector3;
char x;
myvector2.Set(1,2,3);
myvector.Set(1, 2, 3);
myvector3 = myvector; //This works
myvector3 = myvector + myvector2; // this is the line that gives the error
cout<<myvector3.x<<myvector3.y<<myvector3.z; // works without the previous line
cin>>x;
return 1;
}