I am trying to pass a C++ member function as a C style callback to a C library. The code below is what I have so far, using C++11 bind. Compiler is VS 2015.
The code works if I don't use windows __stdcall compiler extension. But, if I do , I get the error:
error C2893: Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...)'
The compiler doesn't like the cast. at the end of the code sample.
cannot determine which instance of 'Callback......" is intended.
// C style callback
typedef void (__stdcall *callback_t)(cl_event evt, cl_int cmd_exec_status, void *encodeData);
// C++ callback
template <typename T> struct Callback;
template <typename Ret, typename... Params> struct Callback<Ret(Params...)> {
template <typename... Args>
static Ret callback(Args... args) {
func(args...);
}
static std::function<Ret(Params...)> func;
};
template <typename Ret, typename... Params> std::function<Ret(Params...)> Callback<Ret(Params...)>::func;
class A {
A() {
void __stdcall ClusterEncoder::e(cl_event evt, cl_int cmd_exec_status, void *encodeData) {
Callback<void(cl_event, cl_int, void*)>::func = std::bind(&ClusterEncoder::e, this, std::placeholders::_3);
callback_t func = static_cast<callback_t>(Callback<void(cl_event, cl_int, void*)>::callback);
}
};
Aucun commentaire:
Enregistrer un commentaire