I spent a whole day to figure out what's going on in my C++ code with a lot of templates. The lesson:
Because the compiler will miss A LOT of errors which could have been detected if you don't. When you have errors in the template, it is the linker, not the compiler that will complain. And the worse thing is when the linker complains, it gives you completely misleading messages.
The other two sources of errors were 1) forgetting to give dummy implementations for constructor and destructor; 2) forgetting to typecast the pointer to the father class into that to the daughter class for accessing daughter-specific fields.
P.S. The most relevant documentation is here. Time to spend more time reading geeky online user's manual and/or documents. :(
ALWAYS INSTANTIATE YOUR TEMPLATES!or
INCLUDE THE IMPLEMENTATIONS OF YOUR TEMPLATES!
Because the compiler will miss A LOT of errors which could have been detected if you don't. When you have errors in the template, it is the linker, not the compiler that will complain. And the worse thing is when the linker complains, it gives you completely misleading messages.
The other two sources of errors were 1) forgetting to give dummy implementations for constructor and destructor; 2) forgetting to typecast the pointer to the father class into that to the daughter class for accessing daughter-specific fields.
P.S. The most relevant documentation is here. Time to spend more time reading geeky online user's manual and/or documents. :(
Comments