When I attempt to use the calculate function, I get the undefined reference error. It seems that the compiler doesn't recognize that the calculate function is implemented in the source file calculation.cpp, because if I copy the implantation into the header file for all the class functions, the error disappears.
Here is how I implemented it in the source file:
#include "calculation.h"
using namespace Calc;
/*****************************************************************/
template <class T, class E, class Q>
Q& Calculation<T, E, Q>::calculate(const char& op)
{
switch (op) {
case '+':
return add();
break;
case '-':
return sub();
break;
case '*':
return mul();
break;
case '/':
return div();
break;
default:
break;
}
There is an article about this, but I can't find it.
This is the idea:
You can't have a cpp if you work with templates. However if you want to have separate file with the implementation do this #include "calculation.hpp" at the end of the header file (I change the extension)