in c++, i use template class AutoRegisterTemplate to do some automatic registration in…
Jump to turn (9)
- 1in c++, i use template class AutoRegisterTemplate to do some automatic registrat
- 2Declare your template class as inline analyze the pros and cons of this behaviou
- 3how to declare a template class to be inline
- 4i did this, i got inline specifier is ignored when there are no declarators
- 5in c++ if a cpp file is not used, it will not be linked. how to change this to m
- 6are there better ways to do this, since adding global variable is not a good ide
- 7is there a way to force link source files to produce static library using cmake
- 8settargetproperties(mylibrary PROPERTIES LINKFLAGS “-Wl,–whole-archive $ -Wl,–no
- 9name all the properties that settargetproperties can set
- User
in c++, i use template class AutoRegisterTemplate to do some automatic registration in class constructor. Suppose ModuleClass is the template parameter, for different ModuleClass , the constructor extract their
ModuleClass::Registerfunction pointer in a static std::map variable all_register_funcs. Now i have this problem, I writestatic AutoRegisterTemplate<ModuleClassA> file_local_varin a .cpp file my_module_a.cpp, hoping ModuleClassA will trigger it's constructor and inturn put ModuleClassA::Register pointer into theall_register_funcs. However, when I run the program, the .cpp file my_module_a.cpp was never linked, it seems that this cpp file was optimized away by linker. Is this a template thing? how do i avoid the problem and achive my goal of using the instantiation mechanic of template to do automatic registration. - Assistant