I am trying to access a static member function defined inside a class template. In the TemplateTest.h header file, I defined the primary class template as:
#include<iostream> template<class T, class U> struct TemplateTest { public: void static invoke(); };
Then the source file TemplateTester.cpp placed the 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 created an instance of the class, so that link replication is correct.
In driver.cpp driver:
include "TemplateTest.h" int main() { TemplateTest<int, bool>::invoke(); return 0; }
When I compile TemplateTest.cpp with g ++, it correctly generates an object file, but when I try to link it to a driver class, it gives my linker error "undefined link to" TemplateTest :: invoke () "
I have looked at other related publications, such as this one , but I am not trying to access the function template.
Any hint is greatly appreciated.
jazaman
source share