What are the disadvantages of using templates?

前端 未结 11 720
生来不讨喜
生来不讨喜 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:37

    The only real disadvantage is that if you make any tiny syntax error in a template (especially one used by other templates) the error messages are not gonna be helpful... expect a couple pages of almost-unusable error msgs;-). Compilers' defect are very compiler-specific, and the syntax, while ugly, is not really "complex". All in all, though -- despite the huge issue with proper error diagnostics -- templates are still the single best thing about C++, the one thing that might well tempt you to use C++ over other languages with inferior implementations of generics, such as Java...

提交回复
热议问题