mardi 27 septembre 2016

lambda calling another external lambda

I can easily do this:

auto f = []()->int { return 4; };
auto g = [f]()->int { return f(); });
int i = g();

Nevertheless, I cannot do this:

int (*f)() = []()->int { return 4; };
int (*g)() = [f]()->int { return f(); });
int i = g();

Why I got such message in MSVC?

error C2440: 'initializing' : cannot convert from 'ClassName::functionName::< lambda_b2eebcdf2b88a20d8b40b0a03c412089>' to 'int (__cdecl *)(void)'

This occurs on line: int (*g)() = f->int { return f(); });

How to do this properly?

Aucun commentaire:

Enregistrer un commentaire