This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: friend operators


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
=======================================================================


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]