Template Compilation Model Part 2

Template Compilation Model Part 2 - Template Compilation...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Template Compilation Model Part 2 Jonathan Schilling, jls@sco.com In the last issue, we looked at the "inclusion" model of template compilation, which is the one used by most compilers in practice but which is lacking in several respects. As a reminder, here was the example that illustrated name leakage in the inclusion model: file3.h: template <class T> void f(T); #include "file3.C" file3.C: void g(int); template <class T> void f(T t) { g(0); } caller3.C: #include "file3.h" void g(long); void h() { f(3.14); g(1); // should call g(long), but calls g(int) instead } Now we'll look at the newly-specified template separate compilation model that has recently been added to the standard. There isn't space here to go into a full description of the new rules, and in fact the complexity of this subject rapidly approaches infinity! But here are some of the key highlights: Names in template functions are divided into those that are dependent upon the template arguments, and those that are not. This distinction is made syntactically, making it easier for people and compilers to understand. Names in template functions that are not dependent upon the template arguments are resolved only in the template definition context (an example would be g(0) in file3.C above).
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/27/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue University-West Lafayette.

Page1 / 3

Template Compilation Model Part 2 - Template Compilation...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online