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]













0















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.










share|improve this question

















  • 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















0















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.










share|improve this question

















  • 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













0












0








0








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.










share|improve this question














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++






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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












  • 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












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
);



);













draft saved

draft discarded


















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















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme