Difference between instantiation and specialization in c++ templates

前端 未结 6 970
眼角桃花
眼角桃花 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:33

    What is the difference between specialization and instantiation in context of C++ templates?

    Normally (no specializations present) the compiler will create instantiations of a template when they are used, by substituting actual template parameters (int in your example) for the formal template parameters (T) and then compile the resulting code.

    If a specialization is present, then for the (set of) special template parameter(s) specified by that specialization, that specialization's implementation is to be used instead of what the compiler would create.

提交回复
热议问题