Functions that are friend to different classes have to be declared within the classes themselves. This poses the same problem as using "magic literals" instead of variables.
1. I have to maintain each and every signatures I declared in the classes.
2. If one of the friend function declaration is not updated properly the project won't compile.
My question is how one can avoid this error-prone, tedious work?
class A {
///A.cc
public:
friend T fn(){}
}
class B {
///B.cc
public:
friend T fn(){}
}
class C {
///C.cc
public:
friend T fn(){}
}
//other.cc
T fn() {}
> My question is how one can avoid this error-prone, tedious work?
Long-distance friendship does not work well; it makes the code less maintainable.
Error-prone, tedious friend declarations are the least of the problems. Changing the implementation of a class would instantly break the code in other components. Locating and fixing errors (say, a class invariant is violated) that crop up during testing, debugging, or in production would be a major headache.