Horje
c++ pass function as argument Code Example
c++ pass function as argument
class MyClass
{
    public:
        MyClass();

        // Note: No longer marked `static`, and only takes the actual argument
        void Callback(int x);
    private:
        int private_x;
};

MyClass::MyClass()
{
    using namespace std::placeholders; // for `_1`

    private_x = 5;
    handler->addHandler(std::bind(&MyClass::Callback, this, _1));
}

void MyClass::Callback(int x)
{
    // No longer needs an explicit `instance` argument,
    // as `this` is set up properly
    cout << x + private_x << endl;
}




Cpp

Related
pointers mcq sanfoundry Code Example pointers mcq sanfoundry Code Example
passing custom function in sort cpp Code Example passing custom function in sort cpp Code Example
what is imposter syndrome Code Example what is imposter syndrome Code Example
opencv read gif c++ Code Example opencv read gif c++ Code Example
int a=0;     int b=30; Code Example int a=0; int b=30; Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10