While reading Karlsson's Beyond the C++ Standard the author defined the friend function intrusive_ptr_add_ref in the body of class reference_counted (see pg 36). That function is called automatically using Argument Dependent Lookup at the proper time.
Never having seen friend functions defined in the body of a class, I played around and discovered that gcc 4.4.3 requires a forward declaration if not using ADL lookup. In fact, there seems to be no way to reference adl_no without that forward declaration. Is this part of the C++ standard or is it an artifact of gcc? (I don't have Windows box so cannot try VC).
#include <cstdlib>
#include <iostream>
namespace {
void adl_no(); // Remove this and it won't compile with gcc
struct Q {
friend void adl_yes(const Q&) {
std::cout << "adl_yes" << std::endl;
}
friend void adl_no() {
std::cout << "adl_NO" << std::endl;
}
};
}
int main(int argc, char** argv)
{
adl_yes(Q());
adl_no();
return EXIT_SUCCESS;
}