将std :: function传递给std :: set_terminate?

时间:2018-02-06 15:30:27

标签: c++ c++11

如何将std :: function转换为terminate_handler,传递给std :: set_terminate的参数?下面的代码是人为设计的,但也体现了我想要做的事情。

#include <iostream>
#include <functional>

void my_terminate() {
    std::cout << "Terminating." << std::endl;
}

void set_terminate_wrapper(std::function<void()> terminate_func) {
    // Set terminate_func as the terminate function:
    std::set_terminate(/*what goes here?*/);
}

int main() {
    std::function<void()> my_func = my_terminate;
    set_terminate_wrapper(my_func);
    throw 1;
    return 0;
}

0 个答案:

没有答案