Article View: alt.comp.lang.learn.c-c++
Article #835Re: operator<< and namespace
From: Thomas Maeder
Date: Wed, 19 Oct 2005 17:54
Date: Wed, 19 Oct 2005 17:54
32 lines
1872 bytes
1872 bytes
"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.
Technical Details
Message-ID:
<m23bmx4ck6.fsf@madbox2.local>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeed.inode.at!news.hispeed.ch!not-for-mailReferences:
<1129731313.976379.198160@g49g2000cwa.googlegroups.com> <m27jc94izy.fsf@madbox2.local> <1129737626.090999.134650@g49g2000cwa.googlegroups.com>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!news.glorb.com!newsfeed.inode.at!news.hispeed.ch!not-for-mail From: Thomas Maeder <maeder@glue.ch> Newsgroups: alt.comp.lang.learn.c-c++,gnu.g++.help Subject: Re: operator<< and namespace Date: Wed, 19 Oct 2005 19:54:49 +0200 Organization: Cablecom Newsserver Lines: 32 Message-ID: <m23bmx4ck6.fsf@madbox2.local> References: <1129731313.976379.198160@g49g2000cwa.googlegroups.com> <m27jc94izy.fsf@madbox2.local> <1129737626.090999.134650@g49g2000cwa.googlegroups.com> NNTP-Posting-Host: 84-73-152-93.dclient.hispeed.ch Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.hispeed.ch 1129744530 14260 84.73.152.93 (19 Oct 2005 17:55:30 GMT) X-Complaints-To: news@hispeed.ch NNTP-Posting-Date: Wed, 19 Oct 2005 17:55:30 +0000 (UTC) User-Agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux) Cancel-Lock: sha1:dKskW8WIXFYPgS8guNzn8KEKlFM=