类模板纠正错误最近,我读的书:C++ templates: the complete guide
大卫Vandevoorde和尼古拉M.约祖蒂斯写的。gcc编译器不会显示与注射名称
具体地约模板解析从书页126
Class templates also have injected class names, However, they are stranger than ordinary injected class names: They can be followed by template arguments (in which case they are injected class template names), but if they are not followed by template arguments they represent the class with its parameters as its arguments (or, for a partial specialization, its specialization arguments).
相关码从书除外如下引用:
template<template<typename> class TT>
class X
{
};
template <typename T>
class C
{
C* a; //OK, same as "C<T>* a"
C<void> b; // OK
X<C> c; //Error, C without a template argument list does not denote a template
X< ::C>d;
};
int main()
{
return 0;
}
上面的代码示例试图解释援引整体段。
我编译上面的代码中的gcc 4.5.3,其输出:
error: field ‘b’ has incomplete type
因此,我有以下问题:
- 为什么编译器生成完全不同的错误讯息?该书说
b
是可以的,但gcc出错了;与此同时,书中列出的其他错误没有被发现?为什么,这是书中可能出现的编译器错误或错误? - 是什么
injected class names
意思?如何才能辨别哪些名字是injected class names
,哪些不是? - 为什么
C*a
是一样的C<T>* a
?我试着用C<T>* a
更换C*a
,未报告任何错误,所以是C* a
为C<T>* a
的简写?
非常感谢!
这句法:'模板<模板类TT>'似乎并没有合法的副手我......你确定你正确转录的例子吗? –
2013-04-21 03:53:07
@NathanErnst我是这么认为的,我从书上抄的代码,并检查其是同 – taocp 2013-04-21 03:53:53
'错误,C没有一个模板参数列表不表示template',我没有看到这个错误出现 – iammilind 2013-04-21 03:55:39