Hi again![embarrass]
hopefully, this should be a quick one. After my last thread
(Class Chaos ver. 1)
I had a fully working vector class. Now the only thing I would like to know is, how do I change my vector to be turned into a static library?
This is the vector code:
mglvector.h;
#ifndef MGLVECTOR_H
#define MGLVECTOR_H
/************************************
* mglVector3:- contains x,y, and z *
* all are floats *
************************************/
class mglVector3
{
public:
mglVector3():x(0.0f),y(0.0f),z(0.0f){}
mglVector3(float x_,float y_,float z_);
mglVector3(const mglVector3& mVec);
~mglVector3();
// operators- yay :P XO
mglVector3& operator=(const mglVector3 mVec);
mglVector3& operator=(const float array[3]);
mglVector3& operator+=(const mglVector3& mVec);
mglVector3& operator+=(const float array[3]);
mglVector3& operator-=(const mglVector3& mVec);
mglVector3& operator-=(const float array[3]);
mglVector3& operator*=(float var);
/*standard addition operators
the form this vector+array*/
friend mglVector3 operator+(const mglVector3& mVec,float array[3])
{
return mglVector3(array[0] + mVec.x, array[1] + mVec.y, array[2] + mVec.z);
}
//the form array+this vector
friend mglVector3 operator+(float array[3],const mglVector3& mVec)
{
return mglVector3(array[0] + mVec.x, array[1] + mVec.y, array[2] + mVec.z);
}
//the form this vector+other vector
friend mglVector3 operator+(mglVector3 mVec1,const mglVector3& mVec2)
{
return mglVector3(mVec1.x + mVec2.x, mVec1.y + mVec2.y, mVec1.z + mVec2.z);
}
//the form other vector+this vector
friend mglVector3 operator+(const mglVector3& mVec1,mglVector3 mVec2)
{
return mglVector3(mVec1.x + mVec2.x, mVec1.y + mVec2.y, mVec1.z + mVec2.z);
}
/*standard subtraction operators
the form this vector-array*/
friend mglVector3 operator-(const mglVector3& mVec,float array[3])
{
return mglVector3(mVec.x - array[0], mVec.y - array[1], mVec.z - array[2]);
}
//the form array-this vector
friend mglVector3 operator-(float array[3],const mglVector3& mVec)
{
return mglVector3(array[0] - mVec.x, array[1] - mVec.y, array[2] - mVec.z);
}
//the form this vector-other vector
friend mglVector3 operator-(mglVector3 mVec1,const mglVector3& mVec2)
{
return mglVector3(mVec1.x - mVec2.x, mVec1.y - mVec2.y, mVec1.z - mVec2.z);
}
//the form other vector-this vector
friend mglVector3 operator-(const mglVector3& mVec1,mglVector3 mVec2)
{
return mglVector3(mVec1.x - mVec2.x, mVec1.y - mVec2.y, mVec1.z - mVec2.z);
}
//the form this vector*value
friend mglVector3 operator*(float var,const mglVector3& mVec2)
{
return mglVector3(mVec2.x * var, mVec2.y * var, mVec2.z * var);
}
//the form value*this vector
friend mglVector3 operator*(const mglVector3& mVec1,float var)
{
return mglVector3(mVec1.x * var, mVec1.y * var, mVec1.z * var);
}
float x;
float y;
float z;
protected:
private:
};
mglvector.cpp;
#include "mglvector.h"
/***********************************
* mglVector3 overloaded operators *
* and methods *
***********************************/
mglVector3::~mglVector3()
{
// dtor
}
mglVector3::mglVector3(float x_,float y_,float z_)
{
x=x_;
y=y_;
z=z_;
}
mglVector3::mglVector3(const mglVector3& mVec)
{
x=mVec.x;
y=mVec.y;
z=mVec.z;
}
mglVector3& mglVector3::operator=(const mglVector3 mVec)
{
x=mVec.x;
y=mVec.y;
z=mVec.z;
return *this;
}
mglVector3& mglVector3::operator=(const float array[3])
{
x=array[0];
y=array[1];
z=array[2];
return *this;
};
mglVector3& mglVector3::operator+=(const mglVector3& mVec)
{
x+=mVec.x;
y+=mVec.y;
z+=mVec.z;
return *this;
};
mglVector3& mglVector3::operator+=(const float array[3])
{
x+=array[0];
y+=array[1];
z+=array[2];
return *this;
}
mglVector3& mglVector3::operator-=(const mglVector3& mVec)
{
x-=mVec.x;
y-=mVec.y;
z-=mVec.z;
return *this;
}
mglVector3& mglVector3::operator-=(const float array[3])
{
x-=array[0];
y-=array[1];
z-=array[2];
return *this;
}
mglVector3& mglVector3::operator*=(float var)
{
x*=var;
y*=var;
z*=var;
return *this;
}
Now, this compiles fine as a library,but when I place library and file in the lib and include files of my compiler, and I try to use the vector, I get three errors;
.objs\main.o:main.cpp:(.text+0x224): undefined reference to `mglVector3::~mglVector3()'
.objs\main.o:main.cpp:(.text+0x24e): undefined reference to `mglVector3::~mglVector3()'
.objs\main.o:main.cpp:(.text$_ZN10mglVector3C1Efff[mglVector3::mglVector3(float, float, float)]+0x8): undefined reference to `vtable for mglVector3'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
If it helps, I'm using the latest stable version of Code::Blocks.
I was just wondering what it is that I'm doing wrong?