Article View: alt.comp.lang.learn.c-c++
Article #292Re: std streams and enum?
From: Ulrich Eckhardt
Date: Sun, 21 Dec 2003 23:42
Date: Sun, 21 Dec 2003 23:42
33 lines
2002 bytes
2002 bytes
Maya wrote:
> enum account_t {Zero, One, Two};
> std::istream&
> jme::operator>>(std::istream& is, jme::Account& obj){
> is >> obj.type; // <<======== Here is the problem ****
> return is;
> }
> account.H: In function `std::istream& jme::operator>>(std::istream&,
> jme::Account&)':
> account.H:91: no match for `std::basic_istream<char,
> std::char_traits<char> >&
> >> jme::account_t&' operator <<<<<<<====== This is the problem *****
> ...: candidates are:
Well, how should IOStreams know about your enumeration and how it is
supposed to be written to a stream? One simple solution is to overload the
operator for it, another is to just use a temporary int and a
static_cast<>.
One more note, you can nest enumerations inside classes/structs:
class Account
{
enum Type
{ one, two, three };
};
The fully qualified type is then Account::Type (just like with namespaces).
Uli
--
Questions ?
see C++-FAQ Lite: http://parashift.com/c++-faq-lite/ first !
Technical Details
Message-ID:
<bs5b4n$9rgo7$1@ID-178288.news.uni-berlin.de>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!b078114.adsl.hansenet.DE!not-for-mailReferences:
<3FE649C1.70108@netscape.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 114592,d75aa99f09707fdd X-Google-Attributes: gid114592,public X-Google-Thread: fa69e,d75aa99f09707fdd X-Google-Attributes: gidfa69e,public X-Google-ArrivalTime: 2003-12-21 15:42:17 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!b078114.adsl.hansenet.DE!not-for-mail From: Ulrich Eckhardt <doomster@knuut.de> Newsgroups: alt.comp.lang.learn.c-c++,borland.public.cpp.borlandcpp Subject: Re: std streams and enum? Followup-To: alt.comp.lang.learn.c-c++ Date: Mon, 22 Dec 2003 00:42:15 +0100 Lines: 34 Message-ID: <bs5b4n$9rgo7$1@ID-178288.news.uni-berlin.de> References: <3FE649C1.70108@netscape.net> NNTP-Posting-Host: b078114.adsl.hansenet.de (62.109.78.114) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de 1072050135 10339079 62.109.78.114 ([178288]) User-Agent: KNode/0.7.2