Difference between instantiation and specialization in c++ templates

(Implicit) Instantiation

This is what you refer to as instantiation (as mentioned in the Question)

Explicit Instantiation

This is when you tell the compiler to instantiate the template with given types, like this:

template Struct<char>; // used to control the PLACE where the template is inst-ed

(Explicit) Specialization

This is what you refer to as specialization (as mentioned in the Question)

Partial Specialization

This is when you give an alternative definition to a template for a subset of types, like this:

template<class T> class Struct<T*> {...} // partial specialization for pointers

Leave a Comment