AW: G++ Bug in finding template instanciation
Martin v. Loewis
martin@loewis.home.cs.tu-berlin.de
Wed May 10 10:58:00 GMT 2000
> 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.
More information about the Gcc-bugs
mailing list