dimanche 8 mars 2015

How the linking phase handles template definitions


Template classes/functions are generated at compile time so, what happens when:



  • temp.h contains a template function or class

  • A.cpp uses temp.h's function using int as the type

  • B.cpp uses temp.h's function using int as the type


A and B get compiled, presumably now both object outputs have a function using type int inside of them now. Normally if you define the same thing twice and try to link, errors. So how is the generated definition any different, since it's conceptually suppose to be just a generated definition.




Aucun commentaire:

Enregistrer un commentaire