Hi -
Of course, your "possible solution" is THE solution. The compiler error is exclaiming "?WHAT? foo?!?". Explicitly stating "d.foo()" fixes the problem.
Or you can always refactor your clases
In general, the fact that you're even USING "friend" should probably be regarded as a "yellow flag" that your design might have problems. You're usually much better off refactoring your classes than using "friend".
Here's a great link that might help:
http://www.parashift.com/c++-faq-lite/friends.html
PS:
It's uncoincidental that Java, C# and most (all?) other contemporary OO languages do *not* have a "friend" construct
PPS:
Before somebody flames me, I learned that .Net *does* have a "friend" construct:
Code:
Friend Assemblies in C# and VB.Net
Imports System.Runtime.CompilerServices
Imports System
<Assembly: InternalsVisibleTo("AssemblyB")>
' Friend class.
Friend Class FriendClass
Public Sub Test()
Console.WriteLine("Sample Class")
End Sub
End Class
' Public class with a Friend method.
Public Class ClassWithFriendMethod
Friend Sub Test()
Console.WriteLine("Sample Method")
End Sub
End Class