What is the point of 'protected' in a union in C++

青春壹個敷衍的年華 提交于 2019-12-06 19:43:30

问题


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?


回答1:


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).

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.



来源:https://stackoverflow.com/questions/20196298/what-is-the-point-of-protected-in-a-union-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!