c++ - Error Compiling Code After trying to turn a class into a template -
1>main.obj : error lnk2019: unresolved external symbol "public: __thiscall mylist<class event>::~mylist<class event>(void)" (??1?$mylist@vevent@@@@qae@xz) referenced in function _main
any idea wrong? had working class before , tried template , error above. idea ? i'm little lost.
and in main use :
mylist<event> eventmanager;
templates play oddly c++'s compilation model because aren't executable code - they're templates executable code. consequently, standard model of partitioning class .h/.cpp pair not work correctly templates.
the reason typically break apart class .h file interface , .cpp file implementation normally, .cpp files can compiled separately while referencing code defined in other .cpp files because linker patch of references after files compiled. since .cpp compile down object files containing executable code, work out correctly.
with templates, however, system breaks down. if define template class , put implementations of member functions .cpp file, when compiler compiles file won't find code - templates code, , won't generate object code template methods. consequently, @ link-time, you'll errors every member function tried call on template class because there's no code available.
i don't know sure if what's causing particular error, you're describing looks case, since changed non-template class (probably split across .h/.cpp pair) template class.
to fix problem, traditional c++ solution have .h file template without accompanying source file. can moving of code in source file header. put line in header marking interface stops , implementation begins, like
/* * * * * implementation below point * * * * */
or
/* * * * * here dragons * * * * */
to make point bit clearer.
hope helps!
Comments
Post a Comment