friend operator>> function declaration for a template class

Y

Yu Lianqing

Hi, all

I am writing an overloading operator >> function for a template class
and can't make it right. G++ 3.2 (Redhat8.0) gives the following
errors:

g++ -c list.cxx
In file included from SLinkList.cxx:3,
from list.cxx:1:
SLinkList.h:20: ISO C++ forbids declaration of `type name' with no
type
SLinkList.h:20: friend declaration requires class-key, i.e. `friend
int'
SLinkList.h:20: parse error before `template'
make: *** [list.o] Error 1

Here is the relevant code segments:

// declaration in SLinkList.h
template <class Type>
class SLinkList {
friend template <class Type>
istream& operator>>( istream&, SLinkList<Type>& );
...
};

// definition in SLinkList.cxx
template <class ElemType>
istream& operator>>( istream &is, SLinkList<ElemType> &slist )
{
...
}

Any help appreciated!

Leonard
3/4/2004
 
L

Leor Zolman

Hi, all

I am writing an overloading operator >> function for a template class
and can't make it right. G++ 3.2 (Redhat8.0) gives the following
errors:

g++ -c list.cxx
In file included from SLinkList.cxx:3,
from list.cxx:1:
SLinkList.h:20: ISO C++ forbids declaration of `type name' with no
type
SLinkList.h:20: friend declaration requires class-key, i.e. `friend
int'
SLinkList.h:20: parse error before `template'
make: *** [list.o] Error 1

Here is the relevant code segments:

// declaration in SLinkList.h
template <class Type>
class SLinkList {
friend template <class Type>
istream& operator>>( istream&, SLinkList<Type>& );

Take that word "friend" and move it from before "template" to before
"istream &". You may also want to choose a different name for one of those
template type parameters (don't use "Type" in both places).
-leor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top