为了账号安全,请及时绑定邮箱和手机立即绑定

这种面向密钥的访问保护模式是已知的习惯用法吗?

这种面向密钥的访问保护模式是已知的习惯用法吗?

Matthieu M.在我之前见过的这个答案中提出了一种访问保护模式,但是从来没有自觉地考虑过一种模式:class SomeKey {     friend class Foo;    SomeKey() {}     // possibly make it non-copyable too};class Bar {public:    void protectedMethod(SomeKey);};在这里,只有一个friend密钥类可以访问protectedMethod():class Foo {    void do_stuff(Bar& b) {         b.protectedMethod(SomeKey()); // fine, Foo is friend of SomeKey    }};class Baz {    void do_stuff(Bar& b) {        b.protectedMethod(SomeKey()); // error, SomeKey::SomeKey() is private    }};它允许更多的细粒度访问控制不是制造Foo一个friend的Bar,避免了更多的复杂模式进行代理。有谁知道这种方法是否已经有名称,即已知模式?
查看完整描述

3 回答

?
拉丁的传说

TA贡献1789条经验 获得超8个赞

这就是所谓的律师-客户成语和更多的细节描述存在。


查看完整回答
反对 回复 2019-11-11
  • 3 回答
  • 0 关注
  • 554 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信