Hello,
i can't figure out the error. Appreciate your advise:
error:
src/mqqt.cpp: In member function 'int AWS_MQQT::aws_mqqt_setup(...)':
src/mqqt.cpp:37:51: error: invalid use of non-static member function
while (subscribe(topic_name, mySubCallBackHandler) != 0) {
^
I removed parameters from functions to simplify the code:
How do you set mySubCallBackHandler pointer?
If you assign some member/class function than remember to set this in the following way: mySubCallBackHandler = &AWS_MQQT::some_function;
a member function operates on an object, which is passed as the this pointer
so you may see the member function void Bar::foo(int n); as void foo(Bar *this, int n);
AWS_MQQT::mySubCallBackHandler() does not respect the signature defined by `pSubCallBackHandler_t' because it has an extra AWS_MQQT parameter (the caller object) and then it can't be used for the `subscribe()'
> I removed parameters from functions to simplify the code
yes, but that code is full of ellipsis that causes other compile errors
your testcase should reproduce the error you are having
@ne555:
appreciate your reply.
>. a member function operates on an object, which is passed as this pointer
does it mean that i can't pass the child's member function to the parent's function?.. unless it is "static"?
And if can't, then what is the proper approach ?
>.. yes, but that code is full of ellipsis that causes other compile errors .your test case should reproduce the error you are having
I didn't think of that. Good point. I'll improve on this. thank you!
#include <functional>
//function object
typedef std::function<void (char *topicName, int payloadLen, char *payLoad)> pSubCallBackHandler_t;
int AWS_MQQT::aws_mqqt_setup() {
usingnamespace std::placeholders; //for _1, _2, _3
auto callback = std::bind(&AWS_MQQT::mySubCallBackHandler, this, _1, _2, _3);
//now callback is like a global function that would call this->mySubCallBackHandler(...)
//so that's what we subscribe
subscribe("", callback);
return 0;
}
it would be similar to having an extra void *data parameter on the callback where you would pass the object.