This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: friend operators
- From: Bernd Speiser <bernd dot speiser at uni-tuebingen dot de>
- To: kisa at centropolisfx dot com
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 27 Aug 2002 14:49:19 +0200
- Subject: Re: friend operators
- Organization: Univ. Tuebingen, Inst. f. Organische Chemie
- References: <3D5BDF8D.2FBB3C04@uni-tuebingen.de> <3D6A6A4D.44296C48@centropolisfx.com>
- Reply-to: bernd dot speiser at uni-tuebingen dot de
Gokhan Kisacikoglu wrote:
>
> > void operator<< (string &);
>
> if you encapsulate it within a namespace, don't, it doesn't seem to
> work, you should declare this operator globally for it to work, I've
> seen this work with other compilers, but not with gcc...
>
Thanks for this information. However, I need the namespace in this case.
I've kind of solved the problem in the meantime (following a suggestion
mentioned
in the gcc-bugs mailinglist:
I declare ALL operator<< functions in this class to be friends. Of course, this
means that those taking the class itself as a first argument, I have to give the
class explicitly
such as
friend void operator<< (Quantity &, string &);
friend istream & operator<< (Quantity &, istream &);
so I can write
Quantity Q;
Q << "something";
istream is;
Q << is;
etc.
Bernd
>
--
=======================================================================
Bernd Speiser
Institut f"ur Organische Chemie
Auf der Morgenstelle 18
D-72076 T"ubingen
Germany
phone: +49-7071-2976205 (office) +49-7071-2976242 (laboratory)
fax: +49-7071-295518
e-mail: bernd.speiser@uni-tuebingen.de
Internet: http://www.uni-tuebingen.de/speiser
=======================================================================