Boost logo

Boost Users :

Subject: [Boost-users] boost and c function pointers
From: Matthijs Möhlmann (matthijs_at_[hidden])
Date: 2013-11-29 04:29:00


Hello all,

I'm not sure if this is possible at all, but let me explain:

I have the following function signature:
typedef int (*sasl_callback_ft)(void);

That function in question gets called with unknown amount of parameters
(usually 3 or 4)

Now I want to assign a member function to it:
class admin {
    public:
        int callback_fun(void *context, int id, const char **result,
unsigned *len);
}
boost::function<int(void *, int, const char **, unsigned *)> callback =
    boost::bind(&admin::callback_fun, this, _1, _2, _3, _4);

Obviously the compiler doesn't allow to assign callback to a
sasl_callback_ft var
sasl_callback_ft fun = callback;

I get compiler errors like:
matthijs_at_hammer:~/t2$ clang++ -o main -std=c++11 main.cpp
main.cpp:22:19: error: no viable conversion from 'boost::function<int
(void *,
      int, const char **, unsigned int *)>' to 'sasl_callback_ft'
      (aka 'int (*)()')
        sasl_callback_ft cbfun = cb;
                         ^ ~~
/usr/include/boost/function/function_template.hpp:894:5: note: candidate
      function
    operator safe_bool () const
    ^
1 error generated.

Attached the testcase I made for this.

Regards, Matthijs




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