The following code suffers from infinite recursion. Other than changing the name of GetDistance that's "scoped" in Foo or in Base<Foo> and its derivitive Bar, how would I go about changing this code so that Bar::GetDistance delegates to the GetDistance that's "scoped" in Foo
class
Foo{
public:
friend double GetDistance( Foo& f1, Foo& f2 )
{
return 0; // or some distance metric
}
};
template
<class T>class Base
{
virtual double GetDistance( T& f1, T& f2 ) = 0;
};
class
Bar : Base<Foo>{
public:
/*override*/ double GetDistance( Foo& f1, Foo& f2 )
{
return GetDistance( f1, f2 );
}
};
int
main(){
Bar bar1;
Foo f1, f2;
bar1.GetDistance( f1, f2 );
return 0;
}
Note that
return Foo:GetDistance( f1, f2 );
gives the error:
error C2039: 'GetDistance' : is not a member of 'Foo
Thanks.
Brian

Qualifying a friend function
shauli
You could declare the GetDistance function friend within Foo, and define it at namespace scope.
Then you could qualify the call from Bar, such as
&#321;ukasz Sromek
CraigInCalifornia
Wings_That_Fly
ejb111us
I think that's the right approach: make it static instead. (Aside: it turns out that I no longer use it as a friend function, and there are no private members that need accessing, but I have the option of keeping having both functions in Foo if I ever needed the friend behavior--kind of strange though.)
Thanks, Einar!
CET PRG455