Thinking in C++ Vol 2 - Practical Programming |
Prev |
Home |
Next |
You may have noticed that all our template examples place
fully-defined templates within each compilation unit. (For example, we place
them completely within single-file programs, or in header files for multi-file
programs.) This runs counter to the conventional practice of separating ordinary
function definitions from their declarations by placing the latter in header
files and the function implementations in separate (that is, .cpp)
files.
The reasons for this traditional separation are:
Non-inline function bodies in header files lead to multiple
function definitions, resulting in linker errors.
Hiding the implementation from clients helps reduce compile-time
coupling.
Vendors can distribute pre-compiled code (for a particular
compiler) along with headers so that users cannot see the function
implementations.
Compile times are shorter since header files are smaller.
Thinking in C++ Vol 2 - Practical Programming |
Prev |
Home |
Next |