Bonjour

Le programme suivant compile et fonctionne correctement

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
// Quelques" #include" inutiles, sans aucun doute !
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cmath>
#include <Windows.h>
#include <cstdlib>
 
 
using namespace std;
 
 
void fmap( int (*f)(int ) )
{
    for(int i = 1; i < 10; ++i){ cout<<f(i)<<", "; }
}
 
 
int main()
{
 
    auto m_f = [](int x){ return 3*x; };
 
    for(int i = 1; i < 10; ++i){ cout<<m_f(i)<<", "; }
    cout<<"\n -----\n";
    fmap(m_f);
 
    return 0;
}
Avec ce main() là aussi

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
 
 
int main()
{
     int a = 3;
     auto m_f = [a](int x){ return a*x; };
 
     for(int i = 1; i < 10; ++i){ cout<<m_f(i)<<", "; }
     cout<<"\n -----\n";
//   fmap(m_f);
 
    return 0;
}
Mais si on décommente la ligne 11, il ne compile plus
Le message d'erreur est
error: cannot convert 'main()::<lambda(int)>' to 'int (*)(int)' for argument '1' to 'void fmap(int (*)(int))'
Merci d'éclairer ma lanterne

PS : Windows seven + CodeBlocks + TDM64-GCC Compiler