How to master functor?(done)

How to master functor and what's wrong in the peice of the code below?
Thank's in advance.

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

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

class Node{
public:
    explicit Node(int i = 300){ cout << "Node Constructor has called!" << endl; }
private:
    int _i, _j, _k;
};


typedef function<void(Node&, long, long)> Action;

struct Command{

    Action action;
    UINT  msg;
};

class CommandEXE{

public:
    CommandEXE(long wParam, long lParam)
                            : _wParam(wParam)
                            , _lParam(lParam){
            cout << "CommandEXE called with wParam, lParam" << endl;
    }

private:
    long _wParam;
    long _lParam;
};



Action DerivedAction(CommandEXE cmdexe){

    return [=] (Node& node, long wParam, long lParam){
		cmdexe(node, wParam, lParam);
	};
}

int main(){

    Action a = DerivedAction(CommandEXE(40, 50));

    return 0;
}



At last, the complie error info is:
D:\WinPro\LamdaTaste\main.cpp|82|error: no match for call to '(const CommandEXE) (Node&, long int&, long int&)'
Last edited on
Not sure what you want cmdexe(node, wParam, lParam); to do. If you want this line to work you would have to overload operator() for CommandEXE (or change the type of cmdexe to something that does overload operator()).
Last edited on
Thank you very much. It does I make a mistake and I do understand.
Topic archived. No new replies allowed.