3 ms·
I'd like them extended slightly, in fact. I'd like a friend declaration after an access specifier to apply only until the next access specifier. Eg. class
by PaulDavisThe1st 1y ago
I'd like them extended slightly, in fact. I'd like a friend declaration after an access specifier to apply only until the next access specifier. Eg.
class Foo {
public:
void method_A();
protected:
friend class Bar;
void method_B();
protected:
friend class Baz;
void method_C();
private:
void method_D();
};
anyone can call method_A(), only Bar can call method_B(), only Baz can call method_C() and nobody can call method_D().
You can do this by inheriting from 2 different pure abstract classes, but that feels much kludgier to me.
- leni536 1y agoLook up the passkey idiom.
- PaulDavisThe1st 1y agoNice, but cumbersome with > 1 friend.
- hhhAndrew 1y agoThis is how Eiffel works. Instead of private, protected, public, you specify the set of classes a method can be seen by: `feature {ANY}` for `public:`, feature {NONE} for private, feature {Self} (IIRC) for protected, feature {Foo, Bar} for descendants of Foo and those of Bar, etc.