G++ internals - Templates

Node: Templates Next: Access Control Prev: Coding Conventions Up: Top

Templates

g++ uses the simple approach to instantiating templates: it blindly generates the code for each instantiation as needed. For class templates, g++ pushes the template parameters into the namespace for the duration of the instantiation; for function templates, it's a simple search and replace.

This approach does not support any of the template definition-time error checking that is being bandied about by X3J16. It makes no attempt to deal with name binding in a consistent way.

Instantiation of a class template is triggered by the use of a template class anywhere but in a straight declaration like class A<int> . This is wrong; in fact, it should not be triggered by typedefs or declarations of pointers. Now that explicit instantiation is supported, this misfeature is not necessary.

Important functions:

instantiate_class_template
This function


Next: Access Control Up: Top