This is the mail archive of the gcc-bugs@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]

Re: AW: G++ Bug in finding template instanciation


> Your problem is that you have declared your operator- for
> Wrapper<T>::Iter in the global namespace. Unfortunately for you, the
> standard algorithms are in namespace std, and name lookup proceeds
> from current scope outwards, and stops as soon as a matching name is
> found. That means that if there is an operator- defined in namespace
> std, for *any type at all*, your operator- will never be seen.

That is not the problem. Koenig lookup should work in this example.
In addition, g++ would indicate that *this* is the problem, if
candidates were found in std::; however, it did not list any
candidates (*).

> The solution, as Herb Sutter explains, is to put your classes and
> functions that pertain to them, in a namespace. Now, Koenig lookup
> becomes involved.  When the compiler searches for an operator-, it
> will also look in the namespaces of the operands, and then it will
> find your operator-.

It is not necessary to create a new namespace; Koenig lookup would
also associate the global namespace with the arguments.

If Sutter writes that you have to create a namespace and cannot have
the class and its operators in the global namespace, he is wrong.

Martin

(*) Of course, if all candidates in std:: are templates for which
argument deduction fails, g++ does not list them. It probably should.

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