🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #837

Re: operator<< and namespace

#837
From: Mark P
Date: Wed, 19 Oct 2005 21:55
42 lines
2752 bytes
Thomas Maeder wrote:
> "Al-Burak" <jalqadir@netscape.net> writes:
> 
> 
>>Correction
>>I accidentally forgot to add the name of the namespace
> 
> 
> As suspected.
> 
> 
> 
>>--------- name.cpp
>>std::ostream& operator<<( std::ostream& os, const jme::Name& obj ) {
>>return os << obj.getNameStr(); }
>>std::istream& operator>>( std::istream& is, jme::Name& obj ) {
>>   return is >> obj.str;
>>}
> 
> 
> This is your problem. As defined here, these operators belong to the
> global namespace. But you want them to belong to the namespace jme:
> 
> namespace jme
> {
>   std::ostream &operator<<(std::ostream &os, Name const &obj)
>   {
>     return os << obj.getNameStr();
>   }
> 
>   std::istream &operator>>(std::istream &is, Name &obj)
>   {
>     return is >> obj.str;
>   }
> }
> 
> and you should be fine.

Am I mistaken in thinking that the functions need to be declared in a 
header included by main.cpp?  I see a "friend" declaration in name.hpp 
and a definition in name.cpp, but I thought a friend declaration alone 
did not imply a function declaration.
Technical Details
Message-ID: <Phz5f.2716$D13.1555@newssvr11.news.prodigy.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newscon06.news.prodigy.com!prodigy.net!newsmst01b.news.prodigy.com!prodigy.com!postmaster.news.prodigy.com!newssvr11.news.prodigy.com.POSTED!5a60e384!not-for-mail
References: <1129731313.976379.198160@g49g2000cwa.googlegroups.com> <m27jc94izy.fsf@madbox2.local> <1129737626.090999.134650@g49g2000cwa.googlegroups.com> <m23bmx4ck6.fsf@madbox2.local>

Show Full Headers
Complete Article Headers
X-Google-Thread: 114592,beb845dd377bccf0
X-Google-Thread: 10ba33,beb845dd377bccf0
X-Google-Attributes: gid114592,gid10ba33,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newscon06.news.prodigy.com!prodigy.net!newsmst01b.news.prodigy.com!prodigy.com!postmaster.news.prodigy.com!newssvr11.news.prodigy.com.POSTED!5a60e384!not-for-mail
From: Mark P <usenet@fall2005REMOVE.fastmailCAPS.fm>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041206 Thunderbird/1.0 Mnenhy/0.7.2.0
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: alt.comp.lang.learn.c-c++,gnu.g++.help
Subject: Re: operator<< and namespace
References: <1129731313.976379.198160@g49g2000cwa.googlegroups.com> <m27jc94izy.fsf@madbox2.local> <1129737626.090999.134650@g49g2000cwa.googlegroups.com> <m23bmx4ck6.fsf@madbox2.local>
In-Reply-To: <m23bmx4ck6.fsf@madbox2.local>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 42
Message-ID: <Phz5f.2716$D13.1555@newssvr11.news.prodigy.com>
NNTP-Posting-Host: 64.169.83.211
X-Complaints-To: abuse@prodigy.net
X-Trace: newssvr11.news.prodigy.com 1129758959 ST000 64.169.83.211 (Wed, 19 Oct 2005 17:55:59 EDT)
NNTP-Posting-Date: Wed, 19 Oct 2005 17:55:59 EDT
Organization: SBC http://yahoo.sbc.com
X-UserInfo1: O@ZQBWKDEJTKBPTXHRJD]_\@VR]^@B@MCPWZKB]MPXHZUYICD^RAQBKZQTZTX\_I[^G_KGFNON[ZOE_AZNVO^\XGGNTCIRPIJH[@RQKBXLRZ@CD^HKANYVW@RLGEZEJN@\_WZJBNZYYKVIOR]T]MNMG_Z[YVWSCH_Q[GPC_A@CARQVXDSDA^M]@DRVUM@RBM
Date: Wed, 19 Oct 2005 21:55:59 GMT