mardi 19 février 2019

The right way call list.pop_front in lambda C++?

I'm a newer to C++ lambda. When I want call pop_front() in a lambda function, I got this error. Codes are:

class AAA{
...
}

class BBB{
    list<AAA> aList;

    void function(){
        //lambda function
        setFunc([this](AAA** ptr)->void{
            *ptr = this->aList.front(); //OK
            this->aList.pop_front(); //error:Non-const function 'pop_front' is called on the const object
        });
    }
}

So what is the right way to call pop_front in it?

Aucun commentaire:

Enregistrer un commentaire