"Hicham Mouline" <hi****@mouline.orgkirjutas:
Hello,
I am attempting to change a existing large code base and I have this
situation:
A.hpp
class A {
....
friend void B::member_function1() const;
...
};
When I include B.hpp for the definition of B, I seem to fall in
cross-include situation where the include guards
don't work (or work bad...)
I tried forward declaring class B before A, but it seems the full
definition of B is required
to declare its member function as a friend to A.
Correct.
>
Is there a solution to this?
If it is not possible to move B definition before A, then the simplest
solution is to define the whole (forward-declared) class B as a friend.
Another solution would be to remove the friend declaration and instead
define a member function in A exposing or twiddling the private bits, and
document that only B::member_function1() can call it.
The cleanest solution would be to redesign the code so that friendship is
not required. However, this may require enormous effort in case of an
"existing large code base".
Paavo