I have in MyClass.h file
template<class TemplateClass>
class MyClass{
public:
MyClass(std::string input);
void funcA();
void funcB();
void funcC();
private:
std::string _input;
TemplateClass _myTemplateClass;
}
And in MyClass.cpp file:
template<class TemplateClass>
MyClass<TemplateClass>::MyClass(): _input(input) {}
template<class TemplateClass>
void MyClass<TemplateClass>::funcA(){
std::cout<<" just prints A, doesn't even refer to the TemplateClass";
}
template<class TemplateClass>
void MyClass<TemplateClass>::funcB(){
std::cout<<" just prints B, doesn't even refer to the TemplateClass";
}
template<class TemplateClass>
void MyClass<TemplateClass>::funcC(){
_myTemplateClass.doSomething();
}
In my main.cpp:
#include "MyClass.h"
auto myClass = MyClass<ConcreteClass>("input"); //This results in a undefined symbol error.
Two questions:
Is it necessary to add template on top of every function (funcA, funcB, funcC) definition in MyClass.cpp, even if they don't refer to TemplateClass?
Why do I get an undefined symbol error in my main.cpp when I try to initialize MyClass?