[GH-ISSUE #466] can't use lambda expression for setSaveConfigCallback #393

Closed
opened 2026-02-28 01:25:05 +03:00 by kerem · 5 comments
Owner

Originally created by @liebman on GitHub (Dec 3, 2017).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/466

in my setup() function I have:

    bool save_config = false;
    wm.setSaveConfigCallback([&]()
    {
        save_config = true;
    });

This fails with an error: error: no matching function for call to 'WiFiManager::setSaveConfigCallback(setup()::__lambda1)'

However I also have:

    wm.setAPCallback([](WiFiManager *)
    {
        configColor();
    });

And this works!

Any ideas?

Originally created by @liebman on GitHub (Dec 3, 2017). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/466 in my `setup()` function I have: ``` bool save_config = false; wm.setSaveConfigCallback([&]() { save_config = true; }); ``` This fails with an error: `error: no matching function for call to 'WiFiManager::setSaveConfigCallback(setup()::__lambda1)'` However I also have: ``` wm.setAPCallback([](WiFiManager *) { configColor(); }); ``` And this works! Any ideas?
kerem 2026-02-28 01:25:05 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@DarkFox commented on GitHub (Dec 19, 2017):

You need to call it like this:

    wm.setSaveConfigCallback([]()
    {
        save_config = true;
    });

Since setSaveConfigCallback doesn't take any arguments.

<!-- gh-comment-id:352744973 --> @DarkFox commented on GitHub (Dec 19, 2017): You need to call it like this: ``` wm.setSaveConfigCallback([]() { save_config = true; }); ``` Since setSaveConfigCallback doesn't take any arguments.
Author
Owner

@liebman commented on GitHub (Dec 19, 2017):

@DarkFox correct, I used this where save_config is a local variable:

    bool save_config = false;
    wm.setSaveConfigCallback([&]()
    {
        save_config = true;
    });

It's supposed to capture the save_config variable so I don't need to make it global as its only used in this one function. Maybe its really a tool chain bug?

<!-- gh-comment-id:352770345 --> @liebman commented on GitHub (Dec 19, 2017): @DarkFox correct, I used this where save_config is a local variable: ``` bool save_config = false; wm.setSaveConfigCallback([&]() { save_config = true; }); ``` It's supposed to capture the save_config variable so I don't need to make it global as its only used in this one function. Maybe its really a tool chain bug?
Author
Owner

@DarkFox commented on GitHub (Dec 19, 2017):

Yeah, I was in the same situation. I decided to just make it a static on my wifi handling class. It's not like I've got multiples of it anyway. Though it is poor style.

<!-- gh-comment-id:352773119 --> @DarkFox commented on GitHub (Dec 19, 2017): Yeah, I was in the same situation. I decided to just make it a static on my wifi handling class. It's not like I've got multiples of it anyway. Though it is poor style.
Author
Owner

@tablatronix commented on GitHub (Feb 1, 2018):

Should we not just add WiFiManager* to all callbacks?

<!-- gh-comment-id:362302811 --> @tablatronix commented on GitHub (Feb 1, 2018): Should we not just add WiFiManager* to all callbacks?
Author
Owner

@liebman commented on GitHub (Jun 19, 2018):

fixed with #584

<!-- gh-comment-id:398528006 --> @liebman commented on GitHub (Jun 19, 2018): fixed with #584
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#393
No description provided.