On Nov 2, 3:40*pm, Edek <edek.pienkow...@gmail.com> wrote:
> You need to bring join out to make ADL consider it
>
> namespace n1{
> class X1
> {
> * *friend void join( X1&, X1& );
>
> };
>
> void join (X1&, X1&) {};}
Yes, I know you can define it outside the class for it to be
found in the namespace (by using), but apart from that?
> Local scope has preference in the standard: if there is a local
> symbol, other lookup methods are not attempted, unless you bring
> it in with "using". (I am using non-formal language, see
> the standard on "using" directive). Only then regular overload
> matching kicks in.
My apologies, I was wanting my first example to look like this:
namespace n1{
class X1
{
friend void join( X1&, X1& ){ }
};
}
class Y
{
void join(){}
void foo()
{
n1::X1 xa, xb;
join( xa, xb );
}
};
I've deliberately not defined the friend outside. The question
still stands - can you call join in any other way than by
removing Y's join from the overload set?
> Could you quote directly, I am confused with what you wrote, it does not
> fit anything I can come up with.
Quote Modern C++ Design Ch 7.4:
"However, experience has proven that member functions are not very
suitable for smart pointers. The reason is that the interaction
between member function calls for the smart pointer for the
pointed-to object can be extremely confusing."
I've noticed that in Loki he has, depending on compiler either
defined the friends in the class or in the namespace...
For this reason (ADL not kicking in automatically if overload
exists) I'm beginning to think that this was boosts choice for using
members instead of non-members in their smart pointers.
Kind regards,
Werner
|