Why doesn't C++ have a pointer to member function type?

后端 未结 9 1854
一生所求
一生所求 2020-12-30 07:24

I could be totally wrong here, but as I understand it, C++ doesn\'t really have a native \"pointer to member function\" type. I know you can do tricks with Boost and mem_fu

9条回答
  •  孤独总比滥情好
    2020-12-30 08:05

    As others pointed out, C++ does have a member function pointer type.

    The term you were looking for is "bound function". The reason C++ doesn't provide syntax sugar for function binding is because of its philosophy of only providing the most basic tools, with which you can then build all you want. This helps keep the language "small" (or at least, less mind bogglingly huge).

    Similarly, C++ doesn't have a lock{} primitive like C#'s but it has RAII which is used by boost's scoped_lock.

    There is of course the school of thought that says you should add syntax sugar for everything that might be of use. For better or worse, C++ does not belong to that school.

提交回复
热议问题