草庐IT

TriviallyCopyable

全部标签

c++ - 为什么 std::memcpy 的行为对于不是 TriviallyCopyable 的对象是未定义的?

来自http://en.cppreference.com/w/cpp/string/byte/memcpy:IftheobjectsarenotTriviallyCopyable(e.g.scalars,arrays,C-compatiblestructs),thebehaviorisundefined.在我的工作中,我们长期使用std::memcpy来按位交换不是TriviallyCopyable的对象:voidswapMemory(Entity*ePtr1,Entity*ePtr2){staticconstintsize=sizeof(Entity);charswapBuffer[