[Solved] Copying to std::chrono::milliseconds with memcpy() gives error -Werror=class-memaccess [closed]
The safer way to implement this that doesn’t rely on knowing the internal layout of std::chrono::duration would be to copy to an integer then pass the integer to the duration: std::array<unsigned char, 6> myArray = {123, 123, 112, 0, 15}; int64_t milliseconds = 0; memcpy(&milliseconds, &myArray, 5); std::chrono::milliseconds dest{milliseconds}; 3 solved Copying to std::chrono::milliseconds with … Read more