I am having a bit trouble understanding how to pass this to a callback function which is passed to a library. The function needs to have a specific signature.
the library in question is OCILIB (https://vrogier.github.io/ocilib/doc/html/classocilib_1_1_subscription.html) and trying to pass a class function as the 4th parameter of Register().
It is possible for me to pass it as following without problem
&database::callback // a static function of database
or
[](ocilib::Event &event) // as lambda function
{
}
but it does not have the access to instance variables. I tried to use it like
[&](ocilib::Event &event) // as lambda function
{
}
but the signature do not match, and I get the following error
database.cpp: In member function ‘bool dcn::database::watch(std::__cxx11::string)’:
database.cpp:104:44: error: no matching function for call to ‘ocilib::Subscription::Register(ocilib::Connection&, std::__cxx11::string&, ocilib::Subscription::ChangeTypesValues, dcn::database::watch(std::__cxx11::string)::<lambda(ocilib::Event&)>, unsigned int, unsigned int)’
}, (unsigned int) 7778, (unsigned int) 0);
^
In file included from /usr/include/ocilib.hpp:9194:0,
from /home/ai/dcn/include/main.h:17,
from database.cpp:1:
/usr/include/ocilib_impl.hpp:6650:13: note: candidate: void ocilib::Subscription::Register(const ocilib::Connection&, const ostring&, ocilib::Subscription::ChangeTypes, ocilib::Subscription::NotifyHandlerProc, unsigned int, unsigned int)
inline void Subscription::Register(const Connection &connection, const ostring& name, ChangeTypes changeTypes, NotifyHandlerProc handler, unsigned int port, unsigned int timeout)
^~~~~~~~~~~~
/usr/include/ocilib_impl.hpp:6650:13: note: no known conversion for argument 4 from ‘dcn::database::watch(std::__cxx11::string)::<lambda(ocilib::Event&)>’ to ‘ocilib::Subscription::NotifyHandlerProc {aka void (*)(ocilib::Event&)}’
make[1]: *** [database.o] Error 1
function is defined as
static void callback(ocilib::Event &);
Need your help to untangle this. thanks in advance.