This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Template declaration problem?
- To: "Bruce Eckel" <Eckel at CrestedButte dot net>
- Subject: Re: Template declaration problem?
- From: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Date: 15 Sep 1998 20:07:19 +-300
- Cc: <egcs-bugs at cygnus dot com>, egcs-patches at cygnus dot com, jason at cygnus dot com
- References: <004101bde0c3$58fd9420$0200a8c0@colossus>
Bruce Eckel <Eckel@CrestedButte.net> 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 {
[snip]
> 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
erase.
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 g++.pt?
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil
test.cc