Recently, I was reading the book: C++ templates: the complete guide
written by David Vandevoorde and Nicolai M. Josuttis.
Specifically about template parsing quoting from the book pp 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).
The relevant codes are excepted from the book as follows:
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;
}
The above code example tries to explain the whole quoted paragraph.
I compiled the above code in gcc 4.5.3, it outputs:
error: field ‘b’ has incomplete type
Therefore, I have the following questions:
- Why the compiler generates totally different error messages? the book says
b
is OK, but gcc gave the error; meanwhile, other errors listed in the book are not detected? Why, is this a possible compiler bug or error in book? - What does
injected class names
mean? How can I identify what names areinjected class names
and what are not? - why
C*a
is the same asC<T>* a
? I tried to replaceC*a
withC<T>* a
, no error is reported, so isC* a
a shorthand forC<T>* a
?
Thanks a lot!