multiple definition of template specialization when using different objects

Intuitively, when you fully specialize something, it doesn’t depend on a template parameter any more — so unless you make the specialization inline, you need to put it in a .cpp file instead of a .h or you end up violating the one definition rule as David says. Note that when you partially specialize templates, the partial specializations do still depend on one or more template parameters, so they still go in a .h file.

Leave a Comment