c++ 没有合适的默认构造函数可用_构造/析构/赋值等默认操作必须保持语义一贯性...

88d1a2dee837847928f7feca973e976d.png

C.22: Make default operations consistent

C.22: 保持默认操作的一贯性

Reason(原因)

The default operations are conceptually a matched set. Their semantics are interrelated. Users will be surprised if copy/move construction and copy/move assignment do logically different things. Users will be surprised if constructors and destructors do not provide a consistent view of resource management. Users will be surprised if copy and move don't reflect the way constructors and destructors work.默认操作从概念上讲是配合严密的一整套处理。它们的语义是相互关联的。如果拷贝/移动构造和拷贝/移动赋值做的是逻辑上不同的事情,用户会感到诧异;如果构造函数和析构函数没有为资源管理提供一致的想法,用户会感到诧异;如果拷贝和移动操作没有对应构造函数和析构函数的动作,用户会感到诧异。

Example, bad(反面示例)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值