Get function pointer from std::function when using std::bind

前端 未结 3 1326
逝去的感伤
逝去的感伤 2020-11-29 06:29

I\'m trying to use std::function in conjunction with std::bind, but I\'m having some problems.

This works:

#include 

        
3条回答
  •  隐瞒了意图╮
    2020-11-29 06:46

    This is quite impossible. The whole reason that std::function exists is that function pointers suck horrifically and should never, ever, be used by anyone, ever again, except for the doomed souls bearing the Burning Standards of Hell C interoperation, because they cannot handle functions with state.

    A std::function cannot, in the general case, be converted to a void(*)(). The only reason this works in the first example is because it happens to be a void(*)() originally.

提交回复
热议问题