Possible Duplicate:
Is this key-oriented access-protection pattern a known idiom?
I have class A
and class B
. I want class A
to access one of class B
's private functions; but only that, not everything else. Is that possible?
Some kind of example:
class A {
//stuff
};
class B {
int r; // A cant use this
MagicFriendKeyword A void func(); // A can use this
public:
...
};
If there is one (or few) members functions in class A, that want to use class B's private member functions, then you can declare those one/few functions as friend. E.g.
class B {
// ...
friend void A::mutateB( B * );
// ...
};
See http://en.wikipedia.org/wiki/Friend_function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With