Is there a way to serialize automatically enums as int?
Posted
by FireAphis
on Stack Overflow
See other posts from Stack Overflow
or by FireAphis
Published on 2010-04-15T14:22:00Z
Indexed on
2010/04/15
18:13 UTC
Read the original article
Hit count: 202
Hello,
Is there a way to serialize enums automatically as int? Every time I define a new enum and write
std::stringstream stream;
stream << myenum1;
stream >> myenum2;
the compiler complains that the operators << and >> are not defined. Do you know a way to tell the compiler to treat enums as plain int's?
What makes the problem harder is that, actually, the serialization is inside a template. Something like this:
template <typename T>
void serialize(const T& value)
{
std::stringstream stream;
stream << value;
}
So I cannot add any casts :( Maybe I can specialize it somehow?
Thank you.
© Stack Overflow or respective owner