class A
{
public:
    class FriendKey
    {
        friend class B;
    private:
        FriendKey(){} // private constructor so only B can instantiate a key; not even derived classes can!
    };

    // restricted function is public but can be called only with a FriendKey;
    // no need to make B a friend of A
    void restrictedFunction(..., const FriendKey&);
}