I'm having trouble identifying the problem here as I'm using multiple techniques I am not that familiar with (splitting code into files, templates), so I have recreated it in the simplest way I could think:
classes.h:
class baseClass{ public: virtual void myfunction(double dA, double dB) = 0; //Pure virtual function virtual void myfunction(double dC) = 0;//Overloaded pure virtual function }; class derivedClass1 :baseClass{ public: void myfunction(double dA, double dB)override; void myfunction(double dC)override; }; class derivedClass2 :baseClass{ public: void myfunction(double dA, double dB)override; void myfunction(double dC)override; }; classes.cpp :
#include"classes.h" void derivedClass1::myfunction(double dA, double dB){ //DO STUFF } void derivedClass2::myfunction(double dA, double dB){ //Do different stuff to derivedClass1 } template <class type> void type::myfunction(double dC){ double dA = dC; double dB = 0; //In place of a complex calculation myfunction(dA, dB) //Call the function for the //relevant class and 2 input arguments. } main:
#include"classes.h" int main(){ derivedClass1 example; example.myfunction(1.0); } What I want to do is overload all myfunction for only one input argument with a template function. As there's many derived classes I wanted to use templates. However, when I do something like this I get this error:
error C2063: 'myfunction' : not a function
Is there an easy way to do this or a better way around it? I've tried putting the template in the header file and removing the in class declarations but that doesn't work either.