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

前端 未结 4 2176
醉酒成梦
醉酒成梦 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 23:15

    In C++ 11 (and boost and tr1) we have std::function as a template type for storing functors, lambdas and functions. So you can definitely have the concept of keeping a function value in a variable of type std::function. that variable can also be "empty" meaning that no function (reference) is stored in it. Then it cannot be called.

    The original question relates to that in contrast to C, C++ allows function references. Plus, for compatibility reasons with C a function name can degenerate to a function pointer. But because of overloading things are more "interesting" in C++ than in C.

提交回复
热议问题