添加新成员以复制c-tor / copy o-tor /序列化提醒 [英] add new member to copy c-tor/copy o-tor/serialization reminder

查看:133
本文介绍了添加新成员以复制c-tor / copy o-tor /序列化提醒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几乎所有的c ++项目都有copy c-tor / copy操作符/序列化方法等类。这些常用于所有成员的操作。



但是有时开发人员忘了添加新成员到此函数。

你知道任何容易,不是wrapp所有成员方式,这将提醒开发人员在这个函数中做一些事或写noop(memeber_name_)。

$ b $



PS:单元测试可以防止这个问题,但我想要一些编译时间。

p>

解决方案

将此功能添加到您的单元测试。如果你的单元测试覆盖了序列化/反序列化(例如,通过确保 deser(ser(x))== x ),在单元测试期间。这同样适用于copy ctors。



这不像编译时错误那么理想,但如果你有一个好的单元测试框架,并确保你有适当的覆盖,那么这些忽视的错误将更难做。


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 forgets to add new member to this functions.
Do you know any easy, not wrapp all members way which will remind developers to do something or write noop(memeber_name_) in this functions.

I tried to invent something but got fault.

PS: unit tests could prevent this problem, but I want something compile time.

解决方案

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.

这篇关于添加新成员以复制c-tor / copy o-tor /序列化提醒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆