W
Werner
Hi All,
Here follows a minimal example that fails to compile:
namespace n1{
class X1
{
friend void join( X1&, X1& ){ }
};
}
class Y
{
void join(){}
void foo()
{
struct{ void operator()( n1::X1&, n1::X1& ){ } }join_x;
n1::X1 xa, xb;
join( xa, xb );
}
};
The friend function join is not found because ADL is
"negated" by the Y::join.
Is there any other way to call join defined in X from within foo?
Apart
from moving the call outside the scope of Y (see next example)?
namespace n1{
class X1
{
friend void join( X1&, X1& ){ }
};
}
class Y
{
void join(){}
friend void join_x( n1::X1&, n1::X1& );
void foo();
};
void join_x( n1::X1& xa, n1::X1& xb )
{
join( xa, xb );
}
void Y::foo()
{
n1::X1 xa, xb;
join_x( xa, xb );
}
The reason I'm asking this question is because of Andrei
Alexandrescu's
choice in Modern C++ Design to use friend functions instead of member
functions for reset (compared to boost that does the opposite). I
realize
his rationale is/was to prevent accidental calling of reset for the
contained
type...
Regards,
Werner
Here follows a minimal example that fails to compile:
namespace n1{
class X1
{
friend void join( X1&, X1& ){ }
};
}
class Y
{
void join(){}
void foo()
{
struct{ void operator()( n1::X1&, n1::X1& ){ } }join_x;
n1::X1 xa, xb;
join( xa, xb );
}
};
The friend function join is not found because ADL is
"negated" by the Y::join.
Is there any other way to call join defined in X from within foo?
Apart
from moving the call outside the scope of Y (see next example)?
namespace n1{
class X1
{
friend void join( X1&, X1& ){ }
};
}
class Y
{
void join(){}
friend void join_x( n1::X1&, n1::X1& );
void foo();
};
void join_x( n1::X1& xa, n1::X1& xb )
{
join( xa, xb );
}
void Y::foo()
{
n1::X1 xa, xb;
join_x( xa, xb );
}
The reason I'm asking this question is because of Andrei
Alexandrescu's
choice in Modern C++ Design to use friend functions instead of member
functions for reset (compared to boost that does the opposite). I
realize
his rationale is/was to prevent accidental calling of reset for the
contained
type...
Regards,
Werner