Демо-версия
Код: Выделить всё
#include
#include
#include
#include
enum class MyEnum : uint32_t
{
one = 100,
two,
};
auto deserialize(std::byte* addr, uint32_t& val)
{
memcpy(&val, addr, sizeof(uint32_t));
}
int main()
{
std::byte buf[4] = { std::byte{0x00}, std::byte{0x00}, std::byte{0x00}, std::byte{0x64}};
MyEnum val;
using underlying_type = std::underlying_type_t&;
deserialize(buf, static_cast(val));
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/78652956/how-to-cast-reference-to-enum-to-reference-to-underyling-type-int[/url]