473,385 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

friend operator>> function declaration for a template class

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
Jul 22 '05 #1
2 2403
On 3 Apr 2004 17:17:07 -0800, yu**********@netscape.net (Yu Lianqing)
wrote:
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
--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #2
On 3 Apr 2004 17:17:07 -0800, yu**********@netscape.net (Yu Lianqing)
wrote:
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
--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Roger Leigh | last post by:
I've written a simple container template class to contain a single value. This emits a signal when the value is changed (it's used as a notifier of changes), and listeners can connect to its...
1
by: Yu Lianqing | last post by:
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...
5
by: Joseph Turian | last post by:
Hi guys, I have a class defined as follows: template <class T> class Foo { Foo(bool (*greater_than)(T, T)); ... };
4
by: hall | last post by:
Hi all. I have run into a problem of overloading a templatized operator>> by a specialized version of it. In short (complete code below), I have written a stream class, STR, which defines a...
11
by: Noah Roberts | last post by:
template < typename T > std::istream & operator >(std::istream & in, std::pair<T,T& p) { in >p.first >p.second; return in; } .... std::istream_iterator< std::pair<size_type, size_type
8
by: devphylosoff | last post by:
I can write friend bool operator<(const Integer& left, const Integer& right); but i cannot use virtual bool operator<(const Integer& left, const Integer& right); or bool operator<(const...
14
by: Jess | last post by:
Hi, I read about operator overloading and have a question regarding "operator->()". If I have two classes like this: struct A{ void f(); }; struct B{
6
by: edd | last post by:
Hello all, Is there a way to determine whether a particular type supports the -> operator at compile time? I'm trying to write a template function (or a series of overloads) that will yield the...
6
by: puzzlecracker | last post by:
Say we have this structure: Struct Foo{ .... friend ostream& operator << (ostream& s, Foo & m); ..... }; friend ostream& operator << (ostream& s, Foo & m){
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.