Can someone explain to me why in chapter 13 of the third edition of the C ++ Programming Language, Stroustrup shows the default parameters for function templates, although they are not supported by C ++ (pre C ++ 11)? This is an example given by Straustup in section 13.4.1:
Explicitly specifying a comparison for each call is tedious. Fortunately, it is easy to select a default value, so only unusual comparison criteria should be explicitly specified. This can be implemented by overloading:
template<class T, class C> int compare(const String<T>& str1, const String<T>& str2); // compare using C template<class T> int compare(const String<T>& str1, const String<T>& str2); // compare using Cmp<T>
Alternatively, we can provide a normal convention as an argument to the default template:
template <class T, class C = Cmp<T> > int compare(const String<T>& str1, const String<T>& str2)
and this is a compiler error:
error: default template arguments cannot be used in the Templates function
source share