add new member to copy c-tor/copy o-tor/serialization reminder

前端 未结 4 674
我在风中等你
我在风中等你 2021-01-05 00:10

Almost all c++ projects have classes with copy c-tor/copy operator/serialize method etc. Which usualy doing something with all members.

But sometimes developers forg

4条回答
  •  春和景丽
    2021-01-05 00:25

    Add this functionality to your unit test. If your unit test covers serializaiton/deserialization (for example, by making sure deser(ser(x)) == x), failure to add members to the serialization function would fail during unit testing. The same could work for copy ctors.

    It's not as ideal as compile time errors, but if you have a good unit test framework in place and you make sure that you have proper coverage, then these errors of neglect would be harder to make.

提交回复
热议问题