Rec. 40 Take care to avoid multiple definition of overloaded functions in conjunction with the instantiation of a class template.
It is not possible in C++ to specify requirements for type arguments for class templates and function templates. This may imply that the type chosen by the user, does not comply with the interface as required by the template. For example, a class template may require that a type argument have a comparison operator defined.
Another problem with type templates can arise for overloaded functions. If a function is overload, there may be a conflict if the element type appears explicitly in one of these. After instantiation, there may be two functions which, for example, have the type int as an argument. The compiler may complain about this, but there is a risk that the designer of the class does not notice it. In cases where there is a risk for multiple definition of member functions, this must be carefully documented.
template <class ET> class Conflict { public: void foo( int a ); // What if ET is an int or another integral type? // The compiler will discover this, but ... void foo( ET a ); };
Next section: 9 Functions