This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Template declaration problem?

Bruce Eckel <> writes:

> This compiles and runs with KCC, but has some interesting problems
> compiling with egcs 1.1:

In fact, there are a few bugs in your code that prevent egcs from
compiling it correctly.  First, when you declare:

> template<class T> class Ring {
>   friend class iterator;

Unless Ring<T>::iterator is already declared, this declaration refers
to a class `iterator' in the outer namespace scope, not a nested
class.  So you have to insert a forward declaration of nested class
`iterator' before the friend declaration.

The lack of this declaration causes a name lookup problem in egcs, but
class Ring::iterator won't be granted friendship with the declaration
as it is.

>   class iterator : public list<T>::iterator {
>       return node == x.node;

Note that `node' is not a standardized member of list<T>::iterator;
although it works with the STL distributed with egcs 1.1, it does not
work with the one in the latest snapshot of egcs!

>   iterator insert (iterator position,const T& x){
>     return iterator(r.insert(position, x));
>   }

The only constructor of class Ring<T>::iterator takes more than one
argument; isn't the first argument missing?  Same problem in method

The name lookup problem I refer to only affects friend declarations
that introduce new names in outer namespaces; if the class iterator
had been forward-declared outside the template definition, the correct
class name would be looked up in the member functions of Ring<T>.

Jason, Mark, any idea about how to fix this problem?  May I install
a preprocessed version of the attached test case in

Alexandre Oliva
Universidade Estadual de Campinas, SP, Brasil

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]