How to use 'this' reference in lambda function and still match MQTT-TLS library definitionPassing capturing lambda as function pointerWhat is a lambda (function)?What is an undefined reference/unresolved external symbol error and how do I fix it?Java 8 Lambda function that throws exception?Anyone using ModBus RTU on Galileo gen 2?“no matching function call” with templated functions projecterror: invalid types 'uint16_t aka short unsigned int[uint8_t aka unsigned char]' for array subscriptFunction works when not in namespace else it breaksgcc: Compiling Qt code with lambda functionunsigned int not work on projecterror: invalid conversion from 'void*' to 'const uint8_t* aka const unsigned char*' [-fpermissive]
Delivering sarcasm
Added a new user on Ubuntu, set password not working?
copy and scale one figure (wheel)
How do I color the graph in datavisualization?
Freedom of speech and where it applies
2.8 Why are collections grayed out? How can I open them?
If infinitesimal transformations commute why dont the generators of the Lorentz group commute?
How can Trident be so inexpensive? Will it orbit Triton or just do a (slow) flyby?
Should I stop contributing to retirement accounts?
What was the exact wording from Ivanhoe of this advice on how to free yourself from slavery?
It grows, but water kills it
Must Legal Documents Be Siged In Standard Pen Colors?
How could a planet have erratic days?
Why Shazam when there is already Superman?
Problem with TransformedDistribution
Why can Carol Danvers change her suit colours in the first place?
Are paving bricks differently sized for sand bedding vs mortar bedding?
If a character has darkvision, can they see through an area of nonmagical darkness filled with lightly obscuring gas?
GraphicsGrid with a Label for each Column and Row
Why is so much work done on numerical verification of the Riemann Hypothesis?
Loading commands from file
Why did the EU agree to delay the Brexit deadline?
Has any country ever had 2 former presidents in jail simultaneously?
What is Cash Advance APR?
How to use 'this' reference in lambda function and still match MQTT-TLS library definition
Passing capturing lambda as function pointerWhat is a lambda (function)?What is an undefined reference/unresolved external symbol error and how do I fix it?Java 8 Lambda function that throws exception?Anyone using ModBus RTU on Galileo gen 2?“no matching function call” with templated functions projecterror: invalid types 'uint16_t aka short unsigned int[uint8_t aka unsigned char]' for array subscriptFunction works when not in namespace else it breaksgcc: Compiling Qt code with lambda functionunsigned int not work on projecterror: invalid conversion from 'void*' to 'const uint8_t* aka const unsigned char*' [-fpermissive]
I'm passing a lambda function as a callback to the MQTT-TLS library.
Here is the MQTT-TLS class constructor declaration:
MQTT(char* domain, uint16_t port, void (*callback)(char*,uint8_t*,unsigned int));
I call the MQTT-TLS like this:
void MQTTMsgs::init()
char addr[] = "172.20.10.3";
this->mqttClient = new MQTT(addr, 1883, [](char* topic, byte* payload, unsigned int length)
// inside callback
);
This code works fine. Compiles and life is good. But the problem is, I need access to 'this' inside of the callback. So then, I add 'this' as a reference of the lambda function like so:
this->mqttClient = new MQTT(addr, 1883, [this](char* topic, byte* payload, unsigned int length)
this->accessOtherPropsEtcEtc();
);
And this is where it slburps out. I get this error on compiling:
error: no matching function for call to 'MQTT::MQTT(char [12], int, MQTTMsgs::MQTTMsgs()::<lambda(char*, byte*, unsigned int
error: note: no known conversion for argument 3 from 'MQTTMsgs::MQTTMsgs()::<lambda(char*, byte*, unsigned int)>' to 'void (*)(char*, uint8_t*, unsigned int) aka void (*)(char*, unsigned char*, unsigned int)'
My question is, why does it compile just fine with a lambda function, but errors out when that same lambda function is passed in 'this' as a reference? My guess is that somehow the g++ compiler is setting the type as MQTT instead of void or 'callback' (or something) and therefore the MQTT function definition isn't matching it. Just not sure how the compiler is seeing this. Any ideas on how I can tweak this to match and work with the MQTT-TLS definition?
Still not fluent in C++ yet. Lots of minutia in this language.
c++ lambda arduino g++
add a comment |
I'm passing a lambda function as a callback to the MQTT-TLS library.
Here is the MQTT-TLS class constructor declaration:
MQTT(char* domain, uint16_t port, void (*callback)(char*,uint8_t*,unsigned int));
I call the MQTT-TLS like this:
void MQTTMsgs::init()
char addr[] = "172.20.10.3";
this->mqttClient = new MQTT(addr, 1883, [](char* topic, byte* payload, unsigned int length)
// inside callback
);
This code works fine. Compiles and life is good. But the problem is, I need access to 'this' inside of the callback. So then, I add 'this' as a reference of the lambda function like so:
this->mqttClient = new MQTT(addr, 1883, [this](char* topic, byte* payload, unsigned int length)
this->accessOtherPropsEtcEtc();
);
And this is where it slburps out. I get this error on compiling:
error: no matching function for call to 'MQTT::MQTT(char [12], int, MQTTMsgs::MQTTMsgs()::<lambda(char*, byte*, unsigned int
error: note: no known conversion for argument 3 from 'MQTTMsgs::MQTTMsgs()::<lambda(char*, byte*, unsigned int)>' to 'void (*)(char*, uint8_t*, unsigned int) aka void (*)(char*, unsigned char*, unsigned int)'
My question is, why does it compile just fine with a lambda function, but errors out when that same lambda function is passed in 'this' as a reference? My guess is that somehow the g++ compiler is setting the type as MQTT instead of void or 'callback' (or something) and therefore the MQTT function definition isn't matching it. Just not sure how the compiler is seeing this. Any ideas on how I can tweak this to match and work with the MQTT-TLS definition?
Still not fluent in C++ yet. Lots of minutia in this language.
c++ lambda arduino g++
1
Possible duplicate of Passing capturing lambda as function pointer
– S.M.
Mar 8 at 4:48
1
One of the answers in the proposed duplicate tells you how to resolve this issue.
– P.W
Mar 8 at 5:24
add a comment |
I'm passing a lambda function as a callback to the MQTT-TLS library.
Here is the MQTT-TLS class constructor declaration:
MQTT(char* domain, uint16_t port, void (*callback)(char*,uint8_t*,unsigned int));
I call the MQTT-TLS like this:
void MQTTMsgs::init()
char addr[] = "172.20.10.3";
this->mqttClient = new MQTT(addr, 1883, [](char* topic, byte* payload, unsigned int length)
// inside callback
);
This code works fine. Compiles and life is good. But the problem is, I need access to 'this' inside of the callback. So then, I add 'this' as a reference of the lambda function like so:
this->mqttClient = new MQTT(addr, 1883, [this](char* topic, byte* payload, unsigned int length)
this->accessOtherPropsEtcEtc();
);
And this is where it slburps out. I get this error on compiling:
error: no matching function for call to 'MQTT::MQTT(char [12], int, MQTTMsgs::MQTTMsgs()::<lambda(char*, byte*, unsigned int
error: note: no known conversion for argument 3 from 'MQTTMsgs::MQTTMsgs()::<lambda(char*, byte*, unsigned int)>' to 'void (*)(char*, uint8_t*, unsigned int) aka void (*)(char*, unsigned char*, unsigned int)'
My question is, why does it compile just fine with a lambda function, but errors out when that same lambda function is passed in 'this' as a reference? My guess is that somehow the g++ compiler is setting the type as MQTT instead of void or 'callback' (or something) and therefore the MQTT function definition isn't matching it. Just not sure how the compiler is seeing this. Any ideas on how I can tweak this to match and work with the MQTT-TLS definition?
Still not fluent in C++ yet. Lots of minutia in this language.
c++ lambda arduino g++
I'm passing a lambda function as a callback to the MQTT-TLS library.
Here is the MQTT-TLS class constructor declaration:
MQTT(char* domain, uint16_t port, void (*callback)(char*,uint8_t*,unsigned int));
I call the MQTT-TLS like this:
void MQTTMsgs::init()
char addr[] = "172.20.10.3";
this->mqttClient = new MQTT(addr, 1883, [](char* topic, byte* payload, unsigned int length)
// inside callback
);
This code works fine. Compiles and life is good. But the problem is, I need access to 'this' inside of the callback. So then, I add 'this' as a reference of the lambda function like so:
this->mqttClient = new MQTT(addr, 1883, [this](char* topic, byte* payload, unsigned int length)
this->accessOtherPropsEtcEtc();
);
And this is where it slburps out. I get this error on compiling:
error: no matching function for call to 'MQTT::MQTT(char [12], int, MQTTMsgs::MQTTMsgs()::<lambda(char*, byte*, unsigned int
error: note: no known conversion for argument 3 from 'MQTTMsgs::MQTTMsgs()::<lambda(char*, byte*, unsigned int)>' to 'void (*)(char*, uint8_t*, unsigned int) aka void (*)(char*, unsigned char*, unsigned int)'
My question is, why does it compile just fine with a lambda function, but errors out when that same lambda function is passed in 'this' as a reference? My guess is that somehow the g++ compiler is setting the type as MQTT instead of void or 'callback' (or something) and therefore the MQTT function definition isn't matching it. Just not sure how the compiler is seeing this. Any ideas on how I can tweak this to match and work with the MQTT-TLS definition?
Still not fluent in C++ yet. Lots of minutia in this language.
c++ lambda arduino g++
c++ lambda arduino g++
asked Mar 8 at 4:38
risingtigerrisingtiger
368114
368114
1
Possible duplicate of Passing capturing lambda as function pointer
– S.M.
Mar 8 at 4:48
1
One of the answers in the proposed duplicate tells you how to resolve this issue.
– P.W
Mar 8 at 5:24
add a comment |
1
Possible duplicate of Passing capturing lambda as function pointer
– S.M.
Mar 8 at 4:48
1
One of the answers in the proposed duplicate tells you how to resolve this issue.
– P.W
Mar 8 at 5:24
1
1
Possible duplicate of Passing capturing lambda as function pointer
– S.M.
Mar 8 at 4:48
Possible duplicate of Passing capturing lambda as function pointer
– S.M.
Mar 8 at 4:48
1
1
One of the answers in the proposed duplicate tells you how to resolve this issue.
– P.W
Mar 8 at 5:24
One of the answers in the proposed duplicate tells you how to resolve this issue.
– P.W
Mar 8 at 5:24
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55056819%2fhow-to-use-this-reference-in-lambda-function-and-still-match-mqtt-tls-library%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55056819%2fhow-to-use-this-reference-in-lambda-function-and-still-match-mqtt-tls-library%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Possible duplicate of Passing capturing lambda as function pointer
– S.M.
Mar 8 at 4:48
1
One of the answers in the proposed duplicate tells you how to resolve this issue.
– P.W
Mar 8 at 5:24