Can I make a bitwise copy of a C++ object?

后端 未结 6 2242
误落风尘
误落风尘 2021-02-09 18:52

Can C++ objects be copied using bitwise copy? I mean using memcopy_s? Is there a scenario in which that can go wrong?

6条回答
  •  春和景丽
    2021-02-09 19:43

    In general if your structure contains pointers, you can't memcpy it because the structure would most likely allocate new memory spaces and point to those. A memcpy can't handle that.

    If however your class only has primitive, non-pointer types, you should be able to.

提交回复
热议问题