Boost logo

Boost :

From: Craig Henderson (cdm.henderson_at_[hidden])
Date: 2002-07-23 16:20:41


>
> There's a trick I use to get rid of the need for "extra" template
parameters
> that might be usefull here...
>
> template<typename Target, typename Source, typename E>
> inline Target lexical_cast(Source arg, E& interpreter =
> (*reinterpret_cast<E*>(0))
> ...

I'm not sure that dereferencing a null pointer in this way to create a
reference this is a good idea. Not least, my test on MSVC does not compile:

    short &t = *(reinterpret_cast<short*>(0));

generates an error
    error C2040: 't' : 'short &' differs in levels of indirection from
'short'

my g++ 2.95.3-5 on cygwin compiles it without error and runs, but as soon as
the variable t is accessed, it generates a Segmentation Fault - I guess an
Access Violation alternative.

-- Craig


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