Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

unions

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?

like image 881
Stefan Avatar asked Nov 25 '13 15:11

Stefan


1 Answers

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.

like image 82
Matteo Italia Avatar answered Sep 28 '22 06:09

Matteo Italia