Boost logo

Boost :

From: Aleksey Gurtovoy (alexy_at_[hidden])
Date: 2002-01-28 13:01:17


Douglas Gregor wrote:
> At one point I tried the same optimization for member
> function pointers as well, but ran into problems portably
> storing member function pointers so that they could safely
> be converted back to their original types.

The usual technique is to declare the type as a pointer to a member function
of an incomplete type, e.g.

    class incomplete;
    typedef void (incomplete::* untyped_mf_pointer)();
    untyped_mf_pointer mf_ptr;

As, at the point of definition, the compiler can't possibly know how much
bytes of storage it would need to store the pointer, it will just use the
maximum possible size for it. (Of course, this is a workaround for
non-conforming optimization that some compilers perform; according to the
standard, 'incomplete' class above may be a complete type as well, and it
shouldn't change anything.)

Aleksey


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