Selfmade friend-classes...
-
while inspecting a piece of code, i discovered the following solution for using friendclasses - the advantage: it's the decision of the friend to be a friend or not:
<font color="#000000" face="Courier New">class MyClass {</font><font color="#000000">
</font><font color="#000000" face="Courier New"> ...</font><font color="#000000">
</font><font color="#000000" face="Courier New">#ifndef CLASS_FRIEND</font><font color="#000000">
</font><font color="#000000" face="Courier New"> protected:</font><font color="#000000">
</font><font color="#000000" face="Courier New">#else</font><font color="#000000">
</font><font color="#000000" face="Courier New"> public:</font><font color="#000000">
</font><font color="#000000" face="Courier New">#endif
...
</font><font color="#000000" face="Courier New">};</font>
-
That's a really entertaining bug waiting to happen. Nothing prevents the compiler from mangling private, protected, and public class member symbols differently; declaring the same class in two compilation units with different accessibility levels for the members is asking for hard-to-diagnose linker errors.