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

Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page

Posting a File and Associated Data to a RESTful WebService preferably as JSON2019 Community Moderator ElectionREST URI convention - Singular or plural name of resource while creating itUploading both data and files in one form using Ajax?How do I upload a file with metadata using a REST web service?REST API - file (ie images) processing - best practicesSpring: JSON data and file in the same requestREST API Put large dataPosting a file and JSON data to Spring rest serviceRESTful Web Service Upload/Download Large Data With JSONREST API Design sending JSON data and a file to the api in same requestPost JSONArray to REST servicePUT vs. POST in RESTParsing values from a JSON file?JavaScript/jQuery to download file via POST with JSON dataHow do I upload a file with metadata using a REST web service?How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?Separate REST JSON API server and client?what's the correct way to send a file from REST web service to client?How do I write JSON data to a file?What is “406-Not Acceptable Response” in HTTP?REST API - file (ie images) processing - best practices