dimanche 23 avril 2017

Nested lambda function

I have the following code:

auto get_functor = [&](const bool check) {
    return  [&](const foo& sr)->std::string {
        if(check){
            return "some string";
        }
        return "another string"
    };
};
run(get_functor(true));

The run function signature:

void run(std::function<std::string(const foo&)> func);

I am getting the following error which is not so clear for me:

error C2440: 'return' : cannot convert from 'main::<lambda_6dfbb1b8dd2e41e1b6346f813f9f01b5>::()::<lambda_59843813fe4576d583c9b2877d7a35a7>' to 'std::string (__cdecl *)(const foo &)'

P.S. I am on MSVS 2013

Aucun commentaire:

Enregistrer un commentaire