How can I simulate alignas(T)?
问题 I have an array which is used as the underlying memory of an object of type T : char memory[sizeof T]; . . . new(memory) T(whatever); How can I make sure memory is aligned correctly for T objects? In C++0x I could just say: alignas(T) char memory[sizeof T]; but Visual Studio 2010 does not support that particular feature yet. 回答1: The usual (portable) solution is to put the memory declaration in a union with whatever built-in type in T requires the most alignment. The simplest way would be to