February 2005
Beginner to intermediate
272 pages
4h 53m
English
In both C and C++, if you don’t call a declared function (or take its address), you don’t have to define it. An analogous situation occurs with member functions of class templates; if you don’t actually call a template’s member function, it’s not instantiated.
This is clearly a handy property for the purpose of reducing code size. If a class template defines a large number of member functions, but you use only two or three of them, you don’t pay the code space penalty for all those unused functions.
An even more important result of this rule is that you can specialize class templates with arguments that would be illegal if all the member functions were instantiated. With this rule in place, it’s possible ...
Read now
Unlock full access