I am developing a C++ class library. The classes have "public" methods aimed at users, and "protected" ones supplying extra services reserved for internal use.
The classes do not derive from each other. In my current model, they need to be explicitly declared friends of each other. Is there a more compact/convenient way to achieve the same effect ?
Example:
class A
{
public:
static int ExposedA() { return 1; }
static int ExposedB();
static int ExposedC();
private:
static int Internal() { return 0; }
friend class B;
friend class C;
};
class B
{
public:
static int ExposedA() { return 2 + A::Internal(); }
static int ExposedB() { return 2; }
static int ExposedC();
private:
static int Internal() { return 0; }
friend class A;
friend class C;
};
class C
{
public:
static int ExposedA() { return 3 + A::Internal(); }
static int ExposedB() { return 3 + B::Internal(); }
static int ExposedC() { return 3; }
private:
static int Internal() { return 0; }
friend class A;
friend class B;
};
int A::ExposedB() { return 1 + B::Internal(); }
int A::ExposedC() { return 1 + C::Internal(); }
int B::ExposedC() { return 2 + C::Internal(); }
In practice, maintenance of the friends list is tedious, and forward references force to move the definitions out of the classes.