Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2000-12-04 08:39:30


> I tried it again, but without success. Using
>
> template< typename T, typename S > T lexical_cast( const S& arg )
>
> and
>
> template<> string lexical_cast< string, char* >( const char*& arg )
>
> results in the following error for me (gcc 2.95.2):
>
> template-id `lexical_cast<string, char *>' for
> `lexical_cast(const char *&)' does not match any template declaration
>
> Is this a bug in the gcc or isn't a compiler required by the standard
> to accept the above?

Write it with the const on the right:

template< typename T, typename S > T lexical_cast( S const & arg );

template<> string lexical_cast< string, char* >( char const * & arg );

Now it is clear that the declarations don't match. You'd need

template<> string lexical_cast< string, char const * >( char const * const &
arg );

but this wouldn't work either, because

lexical_cast<int>("Hello")

is actually

lexical_cast<int, char const (&) [6]>("Hello").

--
Peter Dimov
Multi Media Ltd.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk