在C ++中的联合中“受保护”的意义是什么 [英] What is the point of 'protected' in a union in C++

查看:131
本文介绍了在C ++中的联合中“受保护”的意义是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么可以使用受保护的成员或函数吗?

Is there anything that protected members or functions can be used for?

您不能继承一个联合,所以没有孩子可以访问它。

You cannot inherit from a union so there are no children that can access it. Does it provide a functional use or is just there because removing it was hassle?

推荐答案

protected 联合中完全等同于 private ,但此容限没有任何损害, union struct / 之间的额外差异 (在标准中一起描述)。

protected in a union becomes completely equivalent to private, but this allowance does no harm and avoids extra special case handling and extra differences between union and struct/class (which are described all together in the standard).

老实说,我认为可以使用 protected union 只是为了将第十五个特殊情况添加到标准中来;也许它没有想到标准委员会来区分这种行为,因为它是一个奇怪的角落情况,但没有伤害,因为它目前的规定。

Honestly, I think it's possible to use protected in a union just not to add the umteenth special case to the standard for the sake of it; maybe it didn't even come to mind to the standard committee to differentiate this behavior, since it's quite a bizarre corner case but does no harm as it's currently specified.

这篇关于在C ++中的联合中“受保护”的意义是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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