------- Comment #3 from bangerth at gmail dot com 2009-04-02 22:05 -------
Andrew is right: > static inline bool Read( const char* Str, int& v ) > { v = 0; return true; } > > template< class T > > static inline bool Read( const char* Str, std::vector< T >& v ) > { > T Help; > if ( !Read( Str, Help ) ) Upon seeing the template, the compiler determines the set of possible overloads for the call to Read() -- which consists of the function we're in right now as well as Read(const char*,int&). Upon instantiation with T=MyType, it adds to this list the set of functions named Read from the namespace in which MyType was declared -- i.e. the global namespace, in which no such function is found. So the overload set remains what it was. As a consequence, no overload is found. The fact that other compilers, including earlier versions of gcc, get this wrong is immaterial. W. > return false; > v.push_back( Help ); > return true; > } > } > > struct MyType > { > int i; > }; > > namespace ReadSpace // Extend the namespace ... > { > static inline bool Read( const char* Str, MyType& v ) > { return Read( Str, v.i ); } > } > > using namespace ReadSpace; > > int main() > { > std::vector< MyType > v; > const char* Str = "25"; > return Read( Str, v ) ? 0 : 1; > } > -- bangerth at gmail dot com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution| |INVALID http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36982