Why is it legal to inappropriately access privates in an explicit instantiation?

帅比萌擦擦* 提交于 2019-12-03 02:43:22
Johannes Schaub - litb

It is so that the author of the class that has the private member can explicitly instantiate that member or pass it as an argument as you just did.

The compiler has no idea who is in front of the keyboard, so the access checking here is rather conservative.

Parameters used in explicit instantiation get special treatment because there is no mechanism for a class author to explicitly instantiate a template in an allowed context or to somehow permit doing so with a friend declaration.

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