<yu_kuo@sina.com> wrote in message
news:1187082154.724455.50100@w3g2000hsg.googlegroups.com...
I got series warning when using write enum type to a ostream using
operator<<, like
in call to `std::basic_ostream<_CharT, _Traits>&
std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT =
char, _Traits = std::char_traits<char>]'
A.cpp:60: warning: passing `NAME_ENUM' chooses `int' over `long int'
Compiler gcc 3.4.3
When deserialize from an istream, I have to first using an int, and
then cast to the enum type. And need check the range on the spot.
I do know I can overload operator<< and >> for enum type, but do that
for every enum type isn't too boring? I'm wondering a way to do it in
one strike, is there?
You can overload operator<< and >> for enum type? I didn't think you
could override << >> for C++'s built in types. I'm going to have to play
with that. Right now I'm doing:
int Race, Sex;
is >> CChar.GM >> /* ... */ Race >> Sex /* ... */ ;
CChar.Race = static_cast< ERaces >( Race );
CChar.Sex = static_cast< ESexes >( Sex );
Overloading operator << and >> for my ERaces and ESexes enums would make
it a lot cleaner.
Good enough for me.