So this more of just a general programming question but I am making a simple calculator using templates and I got it working but this is how I have it set up:
template <class T>
class Calculator
{
T a, b;
public:
Calculator (T first, T second)
{a=first; b=second;}
T Add();
T Subtract();
T Multiply();
T Divide();
};
template <class T>
T Calculator<T>::Add ()
{
T retval;
retval = a + b;
return retval;
}
template <class T>
T Calculator<T>::Subtract ()
{
T retval;
retval = a - b;
return retval;
}
template <class T>
T Calculator<T>::Multiply ()
{
T retval;
retval = a * b;
return retval;
}
template <class T>
T Calculator<T>::Divide ()
{
T retval;
retval = a / b;
return retval;
}
Now I have it so it is all in one file called Template.h now when I tried to separate the files like a Template.h and a Template.cpp I was getting some linker errors. This is what the files looked like:
.h:
template <class T>
class Calculator
{
T a, b;
public:
Calculator (T first, T second)
{a=first; b=second;}
T Add();
T Subtract();
T Multiply();
T Divide();
};
.cpp
#include Template.h
template <class T>
T Calculator<T>::Add ()
{
T retval;
retval = a + b;
return retval;
}
template <class T>
T Calculator<T>::Subtract ()
{
T retval;
retval = a - b;
return retval;
}
template <class T>
T Calculator<T>::Multiply ()
{
T retval;
retval = a * b;
return retval;
}
template <class T>
T Calculator<T>::Divide ()
{
T retval;
retval = a / b;
return retval;
}
What do I need to do to be able to seperate them into .h and .cpp files?