How to init this static var

Hi!
I've a template class Application which have a static var. (a pointer to the application instance)

I declare it like this :

static Application<A, T>* app;

I initialize it in the c++ file :

1
2
3
4
5
6
7
8
9
10
#include "../../../include/odfaeg/Graphics/application.h"
namespace odfaeg {
    namespace core {
        using namespace sf;
        template<typename A, typename T>
        Application<A, T>* Application<A, T>::app = nullptr;
        template<typename A, typename T>
        Clock Application<A, T>::timeClk = Clock();
    }
}


My library compiles fine but when I compile my project using my lib, I get this undefined reference error from the linker :

 
C:\mingw64\bin\..\lib\gcc\x86_64-w64-mingw32\14.2.0\..\..\..\..\x86_64-w64-mingw32\bin\ld.exe: obj\Debug\ODFAEG-master\Demos\ODFAEG-DEMO\application.o:application.cp:(.rdata$.refptr._ZN6odfaeg4core11ApplicationIN6sorrok7MyAppliENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE3appE[.refptr._ZN6odfaeg4core11ApplicationIN6sorrok7MyAppliENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE3appE]+0x0)||undefined reference to `odfaeg::core::Application<sorrok::MyAppli, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::app'| 


what's wrong ?
Thanks.
Last edited on
Templates need to be defined in the header file (unless you add explicit template instantiations for all template arguments that you plan to use).
Registered users can post here. Sign in or register to post.