pass function by value (?) instead of function pointer?

前端 未结 4 2174
醉酒成梦
醉酒成梦 2020-12-18 22:28

Sorry if this has been asked before, but I was unable to find it.

So im trying to educate myself about templates and the new C++11 features (mainly lambdas, somethin

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-18 22:58

    A function is implicitly convertible to a pointer to itself; this conversion happens pretty much everywhere. Test(Callback) is exactly the same as Test(&Callback). There is no difference. In both cases, Func is deduced to be void(*)(int).

    Function pointers are weird. You can find out more about them in "Why do all these crazy function pointer definitions all work?"

提交回复
热议问题