What I\’m Learning

September 29, 2007

Templates and multiple-file projects

Filed under: C/C++/C# - .NET, Programming — plusplus @ 10:12 am

I’ve had forgotten this note. Thanks www.cplusplus.com

Because templates are compiled when required, this forces a restriction for multi-file projects: the implementation (definition) of a template class or function must be in the same file as its declaration. That means that we cannot separate the interface in a separate header file, and that we must include both interface and implementation in any file that uses the templates.

Since no code is generated until a template is instantiated when required, compilers are prepared to allow the inclusion more than once of the same template file with both declarations and definitions in a project without generating linkage errors.

REZA++

Blog at WordPress.com.