booker said:
the following codes can pass the compilation in VC6 but not in VC7.1..
is it a bug?
#include <list>
template<class type>
class myclass
{
typedef myclass<type> mytype;
std::list<mytype *>::iterator myit;
}
The error message is correct; it's not a compiler bug.
Whenever you use a type that's a member of a class
that's dependent on a template parameter, you have to
prefix it with "typename". Here, "std::list<mytype*>"
depends on what "type" is. There's no way for the
compiler to know, at the point when it's processing the
definition of the "myclass" template, whether
std::list<myclass<type>*> will even have an "iterator"
member, much less whether that member will be a type or
not, because it doesn't know what "type" will be. For
example, if you have "myclass<X>", someone might have
created an explicit specialization of
std::list<myclass<X>*> that does not declare a member
"iterator", or that declares it to be a data member
rather than a type.
Because the compiler has to know whether a given name
is a type or not in order to parse the code, you have to
tell it that you expect the name you're using to be a
type when the template is eventually instantiated. So,
the line in question should read
typename std::list<mytype*>::iterator myit;
vc++ 6.0 did not enforce this requirement. VC++ 7.1 does
a more thorough job of parsing template definitions and
thus is able to detect the error.
-- William M. Miller