On Tuesday 14 September 2010 23:47:41 Steven Watanabe wrote:
AMDG
Peter Soetens wrote:
When using boost::bind, I can write this:
struct X { void foo(int) {} };
shared_ptr<X> x( new X ); // bind takes shared_ptr: bind(&X::foo, x, 3)();
But I can't write this:
function
foo = &X::foo; // function refuses shared_ptr: foo(x,1); Why doesn't boost::function have the same get_pointer() trick ?
Overload resolution for calling a boost::function is exactly the same as for calling a function with that signature. shared_ptr<X> is not convertible to X*, so the call fails.
So this is by design I presume.
Or how can I rewrite the function signature such that it does work with shared pointers ?
function
foo;
Thank you. The problem was that I didn't know if the first argument was a regular pointer or a shared pointer (generic code!). I have also found another solution, that is, by 'always' writing the call like this: foo(get_pointer(x),1); Which will work for all cases of x, and the signature of foo can remain void(X*,int). Peter