Suppose we have two classes:
class Base
{
private:
int x;
public:
void f();
};
class Foo
{
};
Now everyone can call Base::f(), but I want only to be Fooable to do it.
To achieve this effect, we can make Base::f()private and declare Fooas a friend:
class Base
{
private:
int x;
void f();
friend Foo;
};
The problem with this approach is that it Foohas access both to Base::f()and to Base::x(and even to any other private members Base). But I want Fooonly access to Base::f().
Is there a way for a class (or function) to grant access only to certain private members of another class? Or maybe someone can suggest a better approach to my problem?
EDIT:
, . -, Base - ( ). , Base. Base::f() Foo, . Base::f() , Foo , . Foo Base.