zippy747 wrote:
Are we still pals?
Sorry, I didn't mean to be rude. To make up for it, let me elaborate a
little bit on the suggestion of Victor Bazarov. To me it seems that the
idiom he suggested solves a slightly different problem: how do I make some
private members but not all of them available to a class. Consider:
class Y {
friend class yBuddy; // whatever that is
void y();
friend class yyBuddy; // whatever that is
void yy();
public:
void yyy();
};
class yBuddy { // ah, that's what it is...
static void y(Y& a_y) { a_y.y(); }
friend class X; // aha!
};
class yyBuddy { // ah, that's what it is...
static void yy(Y& a_y) { a_y.yy(); }
friend class Z; // aha!
};
class X {
void bar(Y& a_y) {
a_y.yyy();
yBuddy::y(a_y); // work-around
yyBuddy::yy(a_y); // error
}
};
class Z {
void bar(Y& a_y) {
a_y.yyy();
yBuddy::y(a_y); // error
yyBuddy::yy(a_y); // work-around
}
};
Now, X can call y() and Z can call yy() but X cannot call yy() and Z cannot
call y(). In case that is what you need, by all means go for it. However,
note that it becomes a little more tricky to maintain this code since now
you cannot tell which classes have access to the internals of Y just by
looking at the code of Y. The definitions of access rights gets somewhat
spread out.
Best
Kai-Uwe Bux