I have template member functions, but I cannot figure out how I can instantiate them when I am using them properly. The structure is as follows:
// foo.h
class Foo {
template<typename T>
T Func(T);
}
#include "foo.tpp"
// foo.tpp
template<typename T>
T Func(T input) {return(input);}
How should I instantiate the template if I want to realize the following code in the main function?
//main.cpp
#include "foo.h"
int main()
{
Foo obj;
int int_input, int_output;
int_output = obj.Func(int_input);
double double_input, double_output;
double_output = obj.Func(double_input);
return 0;
}
I have checked answers for similar questions such as Instantiation of template member function, but I do not want to instantiate all the member functions for all combinations every time I use them. Another option might be defining the class as a template class and instantiate different classes using template class Foo<int>;
. However, this forces me to define different classes for different type of member functions, which I do not prefer. Is there other solution? Thank you very much!