tags:

views:

157

answers:

1

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?

+9  A: 

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

AndreyT
And FWIW, they are allowed in C++0x.
GMan
Yes, that's probably what the "Voted to be corrected in the next standard" remark at the linked page is referring to.
AndreyT