Template Implementation Internally

How templates are implemented internally?
Theoretically templates are nothing but a generic routines. But how it has been implemented internally?What complier exactly does?
The compiler usually generates different code for every type that you use with the template.
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?
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
Topic archived. No new replies allowed.