Template Compilation

后端 未结 7 1940
鱼传尺愫
鱼传尺愫 2020-11-29 07:25

I have what could possibly be a dumb question, but I\'m just not understanding my book\'s explanation for it.

It says \"When the compiler sees the definition of a t

7条回答
  •  既然无缘
    2020-11-29 07:48

    I won't straight away generate code. Only generate the class or template code when it comes across an instantiation of that template. Thus if you are actually creating an object of that template definition.

    In essence, templates allow you abstract away from types. If you need two instantiations of the template class for example for an int and a double the compiler will literally create two of these classes for you when you need them. That is what makes templates so powerful.

    I hope my explanation makes some sense.

    All the best

提交回复
热议问题