|
Boost : |
From: Jens Maurer (Jens.Maurer_at_[hidden])
Date: 2001-05-20 15:24:54
John Max Skaller wrote:
> The solution is: ALWAYS declare the function first,
> outside the class. Like this:
>
> void f();
> class X { friend void f(); };
> void f() { .. }
>
> The friend declaration does nothing here except
> let the definition of f get at the private parts of X:
This is fine for non-template classes X and functions f
not taking a parameter of type X.
For the point in question here, declaring the function
first is not a viable option:
namespace N {
template<class T>
class X {
friend void f(T x) { ... }
}
}
X<int> x;
makes exactly N::f(int x) (non-template) available for Koenig
lookup, and no other overload of N::f. I know of no other way to
achieve the same effect other than manually declaring N::f for all
possible types T, of which there are infinitely many.
Jens Maurer
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk