// Barebones code to reproduce the problem: // Interface namespace NS { template<typename T> class X {}; template<typename T> X<T> operator*(const X<T> &a, const X<T> &b); } // Implementation template<typename T> NS::X<T>operator*(const NS::X<T> &a,const NS::X<T> &b) { return NS::X<T>(); } // Application int main(int argc, char *argv[]) { NS::X<int> tmp = NS::X<int>() * NS::X<int>(); } What I get: -bash-3.00$ uname -a Linux elisha.research.canon.com.au 2.6.12-1.1447_FC4smp #1 SMP Fri Aug 26 20:57:13 EDT 2005 i686 i686 i386 GNU/Linux -bash-3.00$ gcc --version gcc (GCC) 4.0.1 20050727 (Red Hat 4.0.1-5) Copyright (C) 2005 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -bash-3.00$ make strange g++ -g strange.cpp -o strange strange.cpp: In function 'int main(int, char**)': strange.cpp:19: error: ambiguous overload for 'operator*' in 'NS::X<int>() * NS::X<int>()' strange.cpp:11: note: candidates are: NS::X<T> operator*(const NS::X<T>&, constNS::X<T>&) [with T = int] strange.cpp:6: note: NS::X<T> NS::operator*(const NS::X<T>&, const NS::X<T>&) [with T = int] make: *** [strange] Error 1 If I place the implementation within the scope of the namespace geometry{...} then it seems to compile fine. However the above does not appear to cause problems using MSVC. Problem exists with gcc 3.3.2 and 3.3.4. Is this code incorrect??? Thanks
the error message about ambiguous overload is correct as there are two functions there. operator* in the global namespace and operator* in the NS namespace. You most likely wanted to implement operator* in the NS namespace and not a new one in the global namespace. The following code does what you wanted to do: // Barebones code to reproduce the problem: // Interface namespace NS { template<typename T> class X {}; template<typename T> X<T> operator*(const X<T> &a, const X<T> &b); } // Implementation template<typename T> NS::X<T>NS::operator*(const NS::X<T> &a,const NS::X<T> &b) { return NS::X<T>(); } // Application int main(int argc, char *argv[]) { NS::X<int> tmp = NS::X<int>() * NS::X<int>(); } Notice how I wrote the Implementation.
Subject: Re: ambiguous overload reported for no obvious reason Thanks - obvious when its pointed out. Sorry for the bother. On Friday 23 September 2005 01:17, pinskia at gcc dot gnu dot org wrote: > The following code does what you wanted to do: ... > Notice how I wrote the Implementation.