I am struggling to access static member function defined inside class template. In the header file TemplateTest.h I defined the primary class Template as:
#include<iostream>
template<class T, class U>
struct TemplateTest
{
public:
void static invoke();
/*{
std::cout << "Should not be called" << std::endl;
}*/
};
Then Source File TemplateTester.cpp I put a specialization:
#include "TemplateTest.h"
template<>
struct TemplateTest<int, bool>
{
static void invoke()
{
std::cout << "invoke<int, bool>" << std::endl;
}
};
template struct TemplateTest<int, bool>; //instantiate to resolve linker issue
I explicitly instantiated the class with so linker resolves correctly.
In the driver driver.cpp :
include "TemplateTest.h"
int main()
{
TemplateTest<int, bool>::invoke();
return 0;
}
When I compile the TemplateTest.cpp with g++ it generates the object file correctly but when I try to link it to the driver class it gives my linker error "undefined reference to `TemplateTest::invoke()"
I went through other related postings like this one but I am not trying access a function template.
Any clue is much appreciated.