help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: operator<< and namespace


From: Thomas Maeder
Subject: Re: operator<< and namespace
Date: Wed, 19 Oct 2005 19:54:49 +0200
User-agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux)

"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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]