I have an enum class as defined here
// namespace Types
enum class MessageType : uint32_t
{
COMPUTE_SUM_MESSAGE = 1
};
I want a function that can take an enum value and convert it to a byte array. I tried to use underlying_type
to convert my enum value from a MessageType
to an uint32_t
but I get a no suitable constructor exists to convert it.
void ConvertMessageTypeToByteArray(Types::MessageType message_type)
{
using MessageTypeUnderlying = std::underlying_type<Types::MessageType>;
// Can not static cast the message_type to MessageTypeUnderlying
MessageTypeUnderlying data = static_cast<MessageTypeUnderlying>(message_type);
}
Is it possible to do something similar to this? I would like to have message_type
as an unsigned 32 bit integer, which is its underlying type.