4/23/08

What are the advantages of templates in C++?

Templates have several advantages.
Firstly, they allow to avoid inappropriate multiple inheritance, where one of the inherited classes is just type to be managed.
Secondly, they allow to inherit from "unknown" type, therefore creating "management" class for unknown type.
Thirdly, templates allow to create "general" classes that is especially useful for all kind of type-safe collection classes.
One good use is building framework classes that unite and hide several internal implementation classes (which can be non-template). This makes it easy for a beginner to use a big integrated complex functional class and still allows advanced users to rewrite portions of actual implementation.

No comments: