C++ lambda as argument. error: use of deleted function
<p>My scheduler class has a method called every where it can accept a function as argument. But when I pass a lambda expression, I got the "error: use of deleted function" error. any tip?</p>

<p>StaticEvent.h</p>

<pre><code>namespace Nugraha { namespace Support { namespace Facades { namespace Scheduler {

template&lt;class Callback&gt;
class StaticEvent : public virtual BaseEvent
{
protected:
    Callback callback;

public:
    StaticEvent(unsigned long interval, Callback callback) : callback(callback)
    {
        this-&gt;interval = interval;
        this-&gt;callback = callback;
    }

    void executeCallback()
    {
        this-&gt;callback();
    }
};

}}}}
</code></pre>

<p>Event.h</p>

<pre><code>namespace Nugraha { namespace Support { namespace Facades { namespace Scheduler {

template&lt;class Callback, class ObjectType&gt;
class Event : public virtual BaseEvent
{
protected:
    Callback callback;
    ObjectType object;

public:
    Event(unsigned long interval, Callback callback, ObjectType object)
    {
        this-&gt;interval = interval;
        this-&gt;callback = callback;
        this-&gt;object   = object;
    }

    void executeCallback()
    {
       ((this-&gt;object)-&gt;*(this-&gt;callback))();
    }
};

}}}}
</code></pre>

<p>Scheduler.h:</p>

<pre><code>namespace Nugraha { namespace Support { namespace Facades { namespace Scheduler {
using Nugraha::Collections::Vector;
using Nugraha::Collections::Collection;

class Scheduler 
{
protected:
    static Collection&lt;BaseEvent*&gt;* EventCollection;

public:
    template&lt;typename Callback&gt;
    static void every(unsigned long interval, Callback callback, int repeatCount = -1)
    {
        EventCollection-&gt;add(new StaticEvent&lt;Callback&gt;(interval, callback));
    }


    template&lt;typename Callback, typename ObjectType&gt;
    static void every(unsigned long interval, ObjectType object, Callback callback, int repeatCount = -1)
    {
        EventCollection-&gt;add(new Event&lt;Callback, ObjectType&gt;(interval, callback, object));
    }

    static void update()
    {
        for(int i=0; i&lt;EventCollection-&gt;count(); i++)
        {
            EventCollection-&gt;getMemberAt(i)-&gt;update(millis());
        }
    }
};

Collection&lt;BaseEvent*&gt;* Scheduler::EventCollection = new Vector&lt;BaseEvent*&gt;();
}}}}
</code></pre>

<p>Then i call it from test.ino:</p>

<pre><code>#include "tests.h"
using Nugraha::Support::Facades::Scheduler::Scheduler;

void setup()
{
    Scheduler::every(2000, []() {
        Serial.println("Hello!");
    });
}

void loop()
{
    Scheduler::update;
}
</code></pre>

<p>Error message:</p>

<pre><code>[Stino - Start building "tests"...]
[ 25%] Creating D:\Code\MicrocontrollerProjects\Stino_Build\tests\tests.ino.cpp.o...
"xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-IC:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266/tools/sdk/include" "-IC:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266/tools/sdk/lwip/include" -c -w -Os -g -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -falign-functions=4 -std=c++11 -MMD -ffunction-sections -fdata-sections  -DF_CPU=80000000L -DLWIP_OPEN_SRC   -DARDUINO=168 -DARDUINO_ESP8266_NODEMCU -DARDUINO_ARCH_ESP8266  -DESP8266 "-IC:\Users\Nugraha\OneDrive\Tugas Akhir Deyen\Code\Fugue\tests" "-IC:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266\cores\esp8266" "-IC:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266\variants\d1" "-IC:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266\libraries\ESP8266WiFi\src" "-IC:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266\libraries\ESP8266HTTPClient\src" "-ID:\Code\MicrocontrollerProjects\libraries\Timer" "-ID:\Code\MicrocontrollerProjects\libraries\ArduinoJson" "D:\Code\MicrocontrollerProjects\Stino_Build\tests\tests.ino.cpp" -o "D:\Code\MicrocontrollerProjects\Stino_Build\tests\tests.ino.cpp.o"
In file included from C:/Users/Nugraha/OneDrive/Tugas Akhir Deyen/Code/Fugue/tests/../vendor/nugraha/tugasAkhirWahyu/src/Nugraha/Header/Nugraha.h:39:0,

                 from C:/Users/Nugraha/OneDrive/Tugas Akhir Deyen/Code/Fugue/tests/../vendor/nugraha/tugasAkhirWahyu/tugasAkhirWahyu.h:4,

                 from C:/Users/Nugraha/OneDrive/Tugas Akhir Deyen/Code/Fugue/tests/../vendor/vendor.h:4,

                 from C:/Users/Nugraha/OneDrive/Tugas Akhir Deyen/Code/Fugue/tests/../Fugue.h:16,

                 from C:/Users/Nugraha/OneDrive/Tugas Akhir Deyen/Code/Fugue/tests/tests.h:13,

                 from C:/Users/Nugraha/OneDrive/Tugas Akhir Deyen/Code/Fugue/tests/tests.ino:1:

C:/Users/Nugraha/OneDrive/Tugas Akhir Deyen/Code/Fugue/tests/../vendor/nugraha/tugasAkhirWahyu/src/Nugraha/Header/../Support/Facades/Scheduler/StaticEvent.h: In instantiation of 'Nugraha::Support::Facades::Scheduler::StaticEvent&lt;Callback&gt;::StaticEvent(long unsigned int, Callback) [with Callback = setup()::__lambda0]':

C:/Users/Nugraha/OneDrive/Tugas Akhir Deyen/Code/Fugue/tests/../vendor/nugraha/tugasAkhirWahyu/src/Nugraha/Header/../Support/Facades/Scheduler/Scheduler.h:22:9:   required from 'static void Nugraha::Support::Facades::Scheduler::Scheduler::every(long unsigned int, Callback, int) [with Callback = setup()::__lambda0]'

C:/Users/Nugraha/OneDrive/Tugas Akhir Deyen/Code/Fugue/tests/tests.ino:8:6:   required from here

C:/Users/Nugraha/OneDrive/Tugas Akhir Deyen/Code/Fugue/tests/../vendor/nugraha/tugasAkhirWahyu/src/Nugraha/Header/../Support/Facades/Scheduler/StaticEvent.h:13:24: error: use of deleted function 'setup()::__lambda0&amp; setup()::__lambda0::operator=(const setup()::__lambda0&amp;)'

         this-&gt;callback = callback;

                        ^

C:/Users/Nugraha/OneDrive/Tugas Akhir Deyen/Code/Fugue/tests/tests.ino:6:29: note: a lambda closure type has a deleted copy assignment operator

     Scheduler::every(2000, []() {

                             ^


[Stino - Exit with error code 1.]
</code></pre>