Guys, I’m doing excercises from “The C++ Programming Language 3rd ed.” and on page 340 there is an example of function:
template <class T, class C = Cmp<T> > // Here is a default argument
// But as far as I'm concerned it's illegal to have a default argument in
// a function template
int compare (const String<T>& str1, const String<T>& str2)
{
/*Some code*/
}
So my question is:
Is there a mistake in a book or I’m getting this wrong?
Yes, the book is wrong in this case. It is indeed illegal to use default template arguments in function template declarations.
You can find the reference to that issue here http://www2.research.att.com/~bs/3rd_issues.html