Date: Wed, 7 May 2025 02:30:17 +0200
Hello!
One problem with friendship is that it is all or nothing.
I think there should exist a kind of limited friendship as follows:
class A;
class B {
private:
[[limited]] friend class A;
void x();
private:
void y();
};
where the [[limited]] attribute on the friend declaration means that A is
granted access to the parts of B within the same "access specifier section"
as the friend declaration.
Now, "access specifier section" is a new term and refer to all declarations
between two access specifiers of an aggregate.
That limited is an attribute is because a simple implementation could ignore
it and the code would still work as intended, it would just grant too much
friendship to A.
/MF
One problem with friendship is that it is all or nothing.
I think there should exist a kind of limited friendship as follows:
class A;
class B {
private:
[[limited]] friend class A;
void x();
private:
void y();
};
where the [[limited]] attribute on the friend declaration means that A is
granted access to the parts of B within the same "access specifier section"
as the friend declaration.
Now, "access specifier section" is a new term and refer to all declarations
between two access specifiers of an aggregate.
That limited is an attribute is because a simple implementation could ignore
it and the code would still work as intended, it would just grant too much
friendship to A.
/MF
Received on 2025-05-07 00:30:25