Boost logo

Boost Users :

From: Ben McCart (ben_at_[hidden])
Date: 2007-07-13 00:38:45


There appears to be a defect in bound_memfunc_ptr. This occurs when
using boost::bind macro to bind an object with its class member function
for use with the boost::function pointer.

For example, when using boost::bind to bind an object and associated
class member function to a pointer like this:

     class A
     {
     public:
         void some_function(int i){};
     };

     A a1;
     boost::function<void, int> pfa1;
     pfa1 = boost::bind(&A::some_function, &a1, _1);

...the bound_memfunc_ptr.memfunc_ptr is populated with the address of
A::some_function. However, the bound_memfunc_ptr.obj_ptr apears to be
uninitialized. (pfa1.functor.bound_memfunc_ptr.obj_ptr has an address of
0xcccccccc in MSVC 2005)

The function pointer works just fine to make calls. Internally the
functor is storing the address of a1. However the address of a1 is not
exposed through the bound_memfunc_ptr interface. I have assumed that
the obj_ptr member which is of type void* is supposed to be the address
of a1.

Since a1's address is not exposed, it is not possible to distinguish
between boost::function pointers that point to a1's member
some_function() and any other object of class A. With this condition
boost::function is unsuitable for use in an observer design pattern
since there is no way to distinguish which boost::function pointer
points to an observer when an observer wants to remove itself
(unsubscribe) from an event.

So, does anybody have any recommendations? Is the obj_ptr member
supposed to be what I think it is, or is it for another purpose? Is
there any other way to get at the address of a bound object, so that the
  boost::function pointer can be uniquely identified?

Thanks in advance,
~Ben


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