What are the disadvantages of using templates?

前端 未结 11 700
生来不讨喜
生来不讨喜 2020-12-16 01:02

Some of the disadvantages would be

  1. its syntax is complex
  2. compiler generates extra code
11条回答
  •  天命终不由人
    2020-12-16 01:52

    A disadvantage: template errors are only detected by the compiler when the template is instantiated. Sometimes, errors in the methods of templates are only detected when the member method is instantiated, regardless if the rest of the template is instantiated.

    If I have an error in a method, of a template class, that only one function references, but other code uses the template without that method, the compiler will not generate an error until the erroneous method is instantiated.

提交回复
热议问题