|
From: Hossein H. <ult...@em...> - 2003-12-26 18:43:11
|
Hi Maya,
Sorry if a little bit late!
> Can someone please help me?
> I am using an enum type that I want to store in a std::IOStream object,
> but the compiler [complainer] tells me that the format is not supported.
> enum types are the same as 'const int' right?
Nope! They are not. I checked the Standard and found out that,
in Section 7.2 (Enumeration Decleration) #5, it says that the
underlying type of an enumeration is an integeral type that is
implementation-specific. It doesn't mention anything about
whether it is a const-qualified type or not. Nor does it mention
anything about whether there must be just one candidate
underlying type for a given enum type or are two or more
candidates possible as well.
> namespace jme{
> enum account_t {Zero, One, Two};
> class Account{
> protected:
> account_t type;
>
> ....
> public:
> friend std::istream&
> jme::operator>>(std::istream& is, jme::Account& obj){
> is >> obj.type; // <<======== Here is the problem ****
> return is;
> }
> };
> }
> This gives me an error that reads:
> ====================================================
> 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:
>
> /* Gives me a list of other candidates */
>
> ====================================================
Considering the above citations from the Standard, it seems that
your compiler has found itself not knowing which type to choose
as the underlying type. I think the best solution is to choose
one and clarify it in a way that the compiler understands it.
Furthermore, that long error comment from your compiler is just
'cause it's trying to use the default streaming tools.
Regards,
--Hossein
--
___________________________________________________________
Sign-up for Ads Free at Mail.com
http://promo.mail.com/adsfreejump.htm
|