Function Returning Itself

后端 未结 9 728
鱼传尺愫
鱼传尺愫 2020-11-27 04:59

Is it possible to declare some function type func_t which returns that type, func_t?

In other words, is it possible for a function to retur

9条回答
  •  情书的邮戳
    2020-11-27 05:32

    In other words, is it possible for a function to return itself?

    It depends on what you mean by "itself"; if you mean a pointer to itself then the answer is yes! While it is not possible for a function to return its type a function can return a pointer to itself and this pointer can then be converted to the appropriate type before calling.

    The details are explained in the question comp.lang.c faq: Function that can return a pointer to a function of the same type.

    Check my answer for details.

提交回复
热议问题