Can I memcpy() any type which has a trivial destructor?

前端 未结 4 1062
感情败类
感情败类 2021-02-20 17:02

I do realize is_pod is a sufficient condition for a type to be memcpy-able, but is has_trivial_destructor also sufficien

4条回答
  •  青春惊慌失措
    2021-02-20 17:26

    Although it's generally rare in practice, there may be a situation where a class has a non-trivial copy constructor, along with a trivial destructor. Consider a class with a static member variable that just counts how many times the class has been copied. If you memcpy it, the counter would be inaccurate.

提交回复
热议问题