c++回调函数

C++使用回调函数的一种方法如下:

Example::Example() {}

Example::~Example() {}

int Example::Start() {
    auto callback = [this](const int type)->int {
        this->Callback(type);
        return 0;
    };

    xxx.ReginsterCallback(callback);
    return 0;
}

int Example::Callback(const int type) {
    /* do sth */
}

int main(int argc, char* argv) {
    Example ex;
    ex.Start();
}

 

posted on 2017-10-30 15:53  cfox  阅读(163)  评论(0编辑  收藏  举报

导航