Article View: alt.comp.lang.learn.c-c++
Article #830operator<< and namespace
From: tengereche
Date: Wed, 19 Oct 2005 14:15
Date: Wed, 19 Oct 2005 14:15
57 lines
2519 bytes
2519 bytes
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
Technical Details
Message-ID:
<1129731313.976379.198160@g49g2000cwa.googlegroups.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!g49g2000cwa.googlegroups.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 114592,beb845dd377bccf0,start X-Google-Thread: 10ba33,beb845dd377bccf0,start X-Google-Attributes: gid114592,gid10ba33,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!g49g2000cwa.googlegroups.com!not-for-mail From: "tengereche" <jalkadir@gosonic.ca> Newsgroups: alt.comp.lang.learn.c-c++,gnu.g++.help Subject: operator<< and namespace Date: 19 Oct 2005 07:15:14 -0700 Organization: http://groups.google.com Lines: 58 Message-ID: <1129731313.976379.198160@g49g2000cwa.googlegroups.com> NNTP-Posting-Host: 66.38.206.177 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1129731319 13734 127.0.0.1 (19 Oct 2005 14:15:19 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 19 Oct 2005 14:15:19 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: g49g2000cwa.googlegroups.com; posting-host=66.38.206.177; posting-account=luuO-A0AAAB0wAnzpMJ2DEWN9MFEvFaw