Difference between instantiation and specialization in c++ templates

前端 未结 6 968
眼角桃花
眼角桃花 2020-11-28 23:40

What is the difference between specialization and instantiation in context of C++ templates. From what I have read so far the following is what I have understood about speci

6条回答
  •  醉话见心
    2020-11-29 00:09

    4 concepts:

    (implicit) instantiation: this is what you refer to as instantiation

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

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

    (explicit )specialization: this is what you refer to as specialization

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

    template class Struct {...} //partial specialization for pointers
    

提交回复
热议问题