문제

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top