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

后端 未结 6 2167
误落风尘
误落风尘 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:34

    It depends on the implementation of the C++ object you are trying to copy. In general the owner of the C++ object's memory is the object itself, so trying to "move" or "copy" it with something like memcopy_s is going behind its back which is going to get you in trouble more often than not.

    Usually if a C++ object is intended to be copied or moved, there are APIs within the class itself that facilitate this.

提交回复
热议问题