mercredi 19 décembre 2018

Have a return statement in a lambda function and store the lambda in a std::function<> [duplicate]

This question already has an answer here:

This lambda works and returns correct value when invoked, When i look at the return value, this lambda should be stored in an int variable How is it possible to store this in a std::function

#include <iostream>
#include <functional>
using namespace std;

int main(){
    function<int(void)> f = [](){
    int some_variable = 10;
    // do some calculation
    return some_variable;
    };
    cout<<f();    
}

Ideone link for code

What goes behind the hood to make it work the way it works

Aucun commentaire:

Enregistrer un commentaire