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

前端 未结 1 886
夕颜
夕颜 2021-02-05 20:37

Why on earth would this be allowed:

//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////         


        
相关标签:
1条回答
  • 2021-02-05 21:40

    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.

    0 讨论(0)
提交回复
热议问题