Bjarne可能犯错误? (同时解释模板),还是我还是不明白? [英] Could Bjarne make mistake? (while explaining templates), or I still do not understand?

查看:89
本文介绍了Bjarne可能犯错误? (同时解释模板),还是我还是不明白?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我正在做C ++编程语言第三版的练习。和第340页有一个函数的例子:

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.

你可以在这里找到这个问题的参考 http://www2.research.att.com/~bs/3rd_issues.html

You can find the reference to that issue here http://www2.research.att.com/~bs/3rd_issues.html

这篇关于Bjarne可能犯错误? (同时解释模板),还是我还是不明白?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆