Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the downside of using templates? [duplicate]

Tags:

c++

Possible Duplicate:
What are the disadvantages of using templates?

Reading about templates I found out that for example if you not use a function from a class template, it will not generate code for that(a positive thing). I also saw that you can use compile time porgramming using templates and implement, let's say a factorial example and the result will be know at compile time.
So my question is: what are the negative aspects of using templates ?

Thank you.

like image 813
Adrian Avatar asked May 06 '11 11:05

Adrian


People also ask

What are the disadvantages of using a template?

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.

What are the disadvantages of templates in C++?

There are three primary drawbacks to the use of templates. First, many compilers historically have very poor support for templates, so the use of templates can make code somewhat less portable. Second, almost all compilers produce confusing, unhelpful error messages when errors are detected in template code.

What is a template and what are the advantages and disadvantage of using one?

Templates simplify the creation of documents. Templates can ease our workload and make us feel less stressed, and, at the same time, they increase efficiency. Templates increase the attention of the audience. They help in saving time and money.

What are templates and what are the advantages of using template?

Answer – A template is a sample document that has some pre defined format which contain image or text that may be changed and used by the user easily. It helps you save money and time. Templates promote client satisfaction and clarity. It boosts productivity.


2 Answers

Compile time. Complex, especially recursive templates can take ages to compile.

Error messages. Template error messages are terrifying and generally not very helpful. Concepts would've been great, but sadly the language committee has dropped them from the upcoming standard.

Readability. Templates code can be challenging to read.

Difficulty Much of the underlying tricks rely on not-so-well-known aspects of the language standard, so one needs a decent knowledge of the language to get along with them.

like image 190
Alexander Gessler Avatar answered Oct 31 '22 23:10

Alexander Gessler


In order for clients to use templates you developed, you have to deliver the source code. This is probably the most significant downside I have encountered in practice.

like image 33
Björn Pollex Avatar answered Nov 01 '22 00:11

Björn Pollex