Template Implementation Internally

Feb 25, 2013 at 12:04am
How templates are implemented internally?
Theoretically templates are nothing but a generic routines. But how it has been implemented internally?What complier exactly does?
Feb 25, 2013 at 2:06am
The compiler usually generates different code for every type that you use with the template.
Feb 26, 2013 at 11:36pm
Thanks Peter. It means, executable size would be increased as complier generates different code for every type during compilation time. Then how its different than function overloading? Whats is the advantage of having template over function overloading?
Feb 27, 2013 at 12:50am
closed account (zb0S216C)
CoolTech wrote:
"Then how its different than function overloading?"

After template instantiation, there's no difference between overloading and template functions. Templates are preferred because they [templates] save the programmer's time by automatically detecting which types the function needs to work with and the compiler then provides a function definition for each type. With manually specifying overloads for a function, you run the risk of failing to provide an overload for a type. With templates, however, this isn't a risk.

Wazzak
Last edited on Feb 27, 2013 at 12:52am
Topic archived. No new replies allowed.