且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

指向成员的指针可以绕开成员的访问级别吗?

更新时间:2022-05-13 01:07:57

是的,这是合法的。相关文本位于§14.7.2/ 12,其中涉及显式模板实例化:

Yes, it's legal. The relevant text is at §14.7.2/12, talking about explicit template instantiation:


12常用的访问检查规则 do不适用于用于指定显式实例化的名称。 [注意:特别是,函数声明符中使用的模板参数和名称(包括参数类型,返回类型和异常规范)可能是私有类型或对象,通常无法访问这些对象,并且模板可能是通常无法通过
访问的成员模板或成员函数。 — 尾注]

12 The usual access checking rules do not apply to names used to specify explicit instantiations. [ Note: In particular, the template arguments and names used in the function declarator (including parameter types, return types and exception specifications) may be private types or objects which would normally not be accessible and the template may be a member template or member function which would not normally be accessible. — end note ]

Emhpasis矿。

Emhpasis mine.