This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ADL Help


On Nov 6, 2006, at 4:20 PM, Ian Lance Taylor wrote:

Perry Smith <pedz@easesoftware.com> writes:

There are several pages just like it. In particular this bullet would
seem to apply but it must not for some reason:


| If T is a class type, its associated classes are the class itself and
| its direct and indirect base classes. Its associated namespaces are
| the namespaces in which its associated classes are defined.


It seems like the "here 1" version would be found but it is not.  Can
you help me to understand what I'm missing?

Argument dependent lookup never finds a member function of a class. It only finds functions declared in namespaces.

Don't get confused by the stuff about "associated classes."  Argument
dependent lookup doesn't look at the member functions of an associated
class.  ADL does look at the friend functions of associated classes--
that's why the concept of associated classes exists.

Thank you so much to Ian. I went back and re-read some of my template books as well as the spec. As Ian points out, the classes are not searched -- except for friends... Here is a simple example. As is, it compiles and runs. Remove the #if 0 and it does not compile -- the compiler can not find "unfriendly".


Thank you again...


#include <iostream>


template <typename T>
class C {
    friend void friendly(C<T> const &a)
    {
	std::cout << "friendly" << std::endl;
    }

    static void unfriendly(C<T> const &a)
    {
	std::cout << "unfriendly" << std::endl;
    }
};

int main()
{
    C<int>p;

    friendly(p);
#if 0
    unfriendly(p);
#endif
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]