Wifimanager: can't use lambda expression for setSaveConfigCallback

Created on 3 Dec 2017  路  5Comments  路  Source: tzapu/WiFiManager

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?

bug

Most helpful comment

Should we not just add WiFiManager* to all callbacks?

All 5 comments

You need to call it like this:

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

Since setSaveConfigCallback doesn't take any arguments.

@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?

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.

Should we not just add WiFiManager* to all callbacks?

fixed with #584

Was this page helpful?
0 / 5 - 0 ratings

Related issues

santhoshnp picture santhoshnp  路  6Comments

Andreafoxalarm picture Andreafoxalarm  路  12Comments

bydoctor picture bydoctor  路  5Comments

VladoPortos picture VladoPortos  路  6Comments

Shalabyer picture Shalabyer  路  10Comments