11/20/2015 - 9:16 PM

C++ template gotchas

C++ template gotchas

C++ Template Gotchas

explicit specialization of template member function

explicit specialization of template member function must be unique, thus must be defined in a cpp file rather than .h file. Note: this only applies to template methods inside non-template class

Template member function cannot be virtual!

Virtual functions and templates don't go together - they are into different leagues. Reason is simple - One employs late-binder and other one employs early-binder. Do very well remember that templates are compile-time, unlike generics in other managed languages (like C#). The type of a generic is determined at runtime, depending on how it is instantiated. But in case of templates, type is determined at compile time only.