Код: Выделить всё
void swapMemory(Entity* ePtr1, Entity* ePtr2)
{
static const int size = sizeof(Entity);
char swapBuffer[size];
memcpy(swapBuffer, ePtr1, size);
memcpy(ePtr1, ePtr2, size);
memcpy(ePtr2, swapBuffer, size);
}
< /code>
и никогда не имел никаких проблем. Тем не менее, мой вопрос: < /p>
Почему поведение STD :: memcpy < /code> само по себе не определено при использовании с нетривиально-экологически чистыми объектами? Почему стандарт считает необходимым указать это? The current description says:
If the objects are not TriviallyCopyable (e.g. scalars, arrays, C-compatible structs), the behavior is undefined unless the program does not depend on the effects of the destructor of the target object (which is not run by memcpy< /blockquote>
ps < /strong> < /p>
Комментарий @cubbi: < /p>
Подробнее здесь: https://stackoverflow.com/questions/297 ... e-not-triv
Мобильная версия