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<ElemT ype> &slist )
{
...
}
Any help appreciated!
Leonard
3/4/2004 2 2444
On 3 Apr 2004 17:17:07 -0800, yu**********@ne tscape.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
On 3 Apr 2004 17:17:07 -0800, yu**********@ne tscape.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 changed signal.
i.e. field<int> i(2);
i = 4; // field<int>::m_value = 4; changed signal is emitted.
Currently, the contained value may be accessed via get_value() and
set_value() methods, and for ease of use, operator= and some type
conversions...
|
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 SLinkList.cxx:3,
from list.cxx:1:
SLinkList.h:20: ISO C++ forbids declaration of `type name' with no
|
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));
...
};
|
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 templatized operator>>() as
a member that can deal with the built in C types (int, char, float...)
template <class tType> STR& STR::operator>>(tType & t);
I then attempted to add an overloaded version of this to support my own
|
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
| |
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 Integer& left, const Integer& right);
no.cpp:10: error: bool Integer::operator<(const Integer&, const
|
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{
|
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 raw pointer at "the end of the arrow". For types
that support the operator, I have a reasonable solution, but I'd like
to have a null pointer returned if the operator isn't supported by a
particular object.
|
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){
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |