C++ using function as parameter

后端 未结 3 1014
臣服心动
臣服心动 2020-12-29 06:37

Possible Duplicate:
How do you pass a function as a parameter in C?

Suppose I have a function called

3条回答
  •  Happy的楠姐
    2020-12-29 07:05

    Another way to do it is using the functional library.

    std::function

    Here reads an example, where we would use funct2 inside funct:

    #include 
    using namespace std;
    #include 
    void funct2(int a) {cout << "hello " << a << endl ;}
    
    void funct(int a, function func) {func(a);}
    
    int main() {
        funct(3,funct2);
        return 0;}
    

    output : hello 3

提交回复
热议问题