Thread: Re: [Dev-C++] std streams and enum?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
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
|
|
From: Maya <Esc...@ne...> - 2004-01-08 00:38:26
|
I see what you are saying, but I am in a bit of a problem here. You see,
I'm subscribed to the Dev-C++ mailing list, but I also read the postings
and post messages at "borland.public.cpp.borlandcpp" and
"alt.comp.lang.learn.c-c++" news groups. Now, the people posting
messages to either of the news groups don't see the messages I posted
in Dev-C++, do they? and vise versa. To save me the time of posting the
question at Dev-C++ to latter find out that it was not related to
Dev-C++, but to C++; then post the same question on the news groups so
that they can tell me that the program is OK and that there must be
something else causing the "warning" or "error"; while at the same time
trying to keep everyone involved in the solution informed of what the
others are saying; I decided to post my questions in all three, and
replay to all three, so that all three parties are informed as to what
is going on.
If you know a better method of doing this I would be most interested
about it, but for now I will keep informed the other folks in the news
groups about your reply, which by the way is been of great help. Thank
you so very much! You rule, man!!
Have good one, and if you are having more than one... give a shout
pw...@ia... wrote:
>Once more. Don't query the world. Send query to ONE list. ONE list. ONE
>list. Any more questions to everywhere will be ignored. A number of people
>- often the smartest guys - have already filtered your mail address
>because they care about netiquette.
>
>No, an enum type might have the size of an int, but it is it's own data
>type. You must perform a type-cast to assign to it. What use would
>type-checking of enum types be if you could assign anything to them?
>
>/Per W
>
>On Sun, 21 Dec 2003, Maya wrote:
>
>
>
>>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? So, there should not be a
>>problem!
>>
>>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 */
>>
>>====================================================
>>
>>Thanks in advance
>>--
>>
>>FYI
>>http://www.astro.umd.edu/~marshall/abbrev.html
>>
>>E-Mail Policy
>>http://www.vif.com/users/escalante/Email_Policy.html
>>
>>* You cannot exercise your power to a point of humiliation.
>> - Jean Chretien
>>
>>* The media's the most powerful entity on earth. They have the
>> power to make the innocent guilty and to make the guilty
>> innocent, and that's power.
>> - Malcom X
>>* "Innocent until proven guilty", no... not in Canada!!
>>
>>
>>
>>
>>-------------------------------------------------------
>>This SF.net email is sponsored by: IBM Linux Tutorials.
>>Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
>>Free Linux Tutorials. Learn everything from the bash shell to sys admin.
>>Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
>>_______________________________________________
>>Dev-cpp-users mailing list
>>Dev...@li...
>>TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
>>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>>
>>
>>
>
>
>
>
--
FYI
http://www.astro.umd.edu/~marshall/abbrev.html
E-Mail Policy
http://www.vif.com/users/escalante/Email_Policy.html
* You cannot exercise your power to a point of humiliation.
- Jean Chretien
* The media's the most powerful entity on earth. They have the
power to make the innocent guilty and to make the guilty
innocent, and that's power.
- Malcom X
* "Innocent until proven guilty", no... not in Canada!!
|