Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::bind and Motif
From: Andrew Holden (aholden_at_[hidden])
Date: 2012-05-07 10:31:33


On Friday, May 04, 2012 1:04 PM, Richard wrote:
> static_cast<T*>(p) where p is void* works perfectly fine.
> It is always valid to cast a void* to any other type and
> that's what static_cast<> does -- performs the cast when
> it is allowed by the rules of the language.
>
> You don't need reinterpret_cast<> here.
>
> Did you try it with static_cast?

You learn something new every day. Since static_cast works, then feel
free to change my sample accordingly.

As for your earlier comment about the only "sane" thing being to cast
back to the exact same type after a void* context parameter, that's the
main reason why I suggested a generic helper class. My class takes
complete control of the Xt callback, thus making it extremely difficult
to mess up that cast, and it provides a type-safe interface to your
code. Get it working once, and then reuse it whenever you need an
XtAppTimeout.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net