This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: AW: G++ Bug in finding template instanciation
- To: hymie at prolifics dot com
- Subject: Re: AW: G++ Bug in finding template instanciation
- From: "Martin v. Loewis" <martin at loewis dot home dot cs dot tu-berlin dot de>
- Date: Wed, 10 May 2000 19:47:06 +0200
- CC: kanze at gabi-soft dot de, gcc-bugs at gcc dot gnu dot org
- References: <200005101532.e4AFWAv27796@calumny.jyacc.com>
> 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.