help-gplusplus
[Top][All Lists]
Advanced

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

operator<< and namespace


From: tengereche
Subject: operator<< and namespace
Date: 19 Oct 2005 07:15:14 -0700
User-agent: G2/0.2

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{
calss strtools{
   std::string str;
   ........

};
}

--------- name.hpp
namespace{
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;

}

--------- main.cpp
   jme::Name name("ni\xa4" "a");

   std::cout << "\"" << name << "\"" << std::endl;

   std::cout << "End of name..." << std::endl;
   std::cin.get();
   return 0;

}

========================================

what am I doing wrong?
Does it hava anything to do with my namespace?

TIA



reply via email to

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