[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 17:35:45 +0200 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux) |
"tengereche" <jalkadir@gosonic.ca> writes:
> This program does compile, but the linker says:
> main.o(.text+0x1a4):main.cpp: undefined reference to
> `jme::operator<<(std::ostream&, jme::Name const&)'
>
> here is the program's snips.
>
> --------- strtools.hpp
> namespace{
Are you sure that this isn't
namespace jme {
?
> calss strtools{
> std::string str;
> ........
>
> };
> }
>
> --------- name.hpp
> namespace{
Are you sure that this isn't
namespace jme {
?
Please always copy&paste code. Don't re-type.
> class Name : public jme::strtools{
> ....
> // This only gives you an idea as to what the f'tions do
> const std::string& getNameStr() const{return str;}
> void setName( const std::string& x){str = x;}
> void setName( const char* x){str = x;}
>
> friend std::ostream& operator<<( std::ostream& os,
> const jme::Name& obj );
> friend std::istream& operator>>( std::istream& is,
> jme::Name& obj );
>
> };
> }
>
> --------- 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;
>
> }
These operators belong to the global namespace. Define them in
namespace jme.