TITLE: controlling access without outright friendship (Newsgroups: comp.std.c++, 21 Mar 99) [ This is a related technique to that described in the tip priv_interface. -adc ] BONNARD: Valentin Bonnard [snip] Sometimes I want to allow a class (and only this class) to call some functions (for example to give it access to a registery). One way to do that is to only give this class ctor a pointer or reference to the registery, but this isn't allways possible (when the register and remove functions are part of another class). In this case I use a private key: class Granting { public: class Key { friend class Priviledge; Key () {} Key (const Key&) {} }; void sensitive_function (Key); }; class Priviledge { public: void do_stuff () { g.sensitive_function (Granting::Key ()); } private: Granting& g; }; Priviledge isn't a friend of Granting, not even close; but it can do more than another class or free function.