Alignment of a simple class to allow array access without UB
问题 Suppose I have the following simple class: struct employee{ std::string name; short salary; std::size_t age; employee(std::string name, short salary, std::size_t age) : name{name}, salary{salary}, age{age}{} }; Since I want array-like access to the name member of employee in an array of employees, I need for example that the offsets are divisible: static_assert( sizeof(employee) % sizeof(std::string) == 0, "!" ); In order to ensure that I am using the alignas directive: struct alignas(sizeof