OS: WinXP (SP2) 32-bits
Hello guys,
I played with C::B to try out some new techniques, now I have the following problem.
When compiling the following code:
template <class T>
class GenVar
{
public:
T a;
T b;
public:
GenVar(void) : a(0), b(0) {}
void operator=(const GenVar<T>& var);
GenVar<T> operator+(const GenVar<T>& var);
};
template <class T>
void GenVar<T>::operator=(const GenVar<T>& var)
{
a = var.a;
b = var.b;
}
template <class T>
GenVar<T> GenVar<T>::operator+(const GenVar<T>& var)
{
GenVar<T> temp;
temp.a = a + var.a;
temp.b = b + var.b;
return (temp);
}
int main()
{
double x = 3.56789;
double y = 2.56784;
GenVar<double> m, n, p, q;
m.a = n.a = 2.00234;
m.b = n.b = 5.98457;
p = m+n;
q = p;
cout<<"Adding class objects using templates: a is "<<p.a<<" b is "<<p.b<<endl;
return 0;
}
It compiles fine.
But when putting the class in seperate files GenVar.cpp and GenVar.h I get the following error:
unreferenced to `GenVar<double>::operator+(GenVar<double> const&)'
undefined reference to `GenVar<double>::operator=(GenVar<double> const&)'
This happens when it reaches:
In GenVar.h I have the following code:
template <class T>
class GenVar
{
public:
T a;
T b;
public:
GenVar(void) : a(0), b(0) {}
void operator=(const GenVar<T>& var);
GenVar<T> operator+(const GenVar<T>& var);
};
And in GenVar.cpp I have the following code:
#include "GenVar.h"
template <class T>
void GenVar<T>::operator=(const GenVar<T>& var)
{
a = var.a;
b = var.b;
}
template <class T>
GenVar<T> GenVar<T>::operator+(const GenVar<T>& var)
{
GenVar<T> temp;
temp.a = a + var.a;
temp.b = b + var.b;
return (temp);
}
These files are in the same directory as main.cpp.
I think it's a linking problem, but please help me out, I already don't have hair on my head, cause ripped it all off

Thank you.