Does using callbacks in C++ increase coupling?

前端 未结 8 1825
予麋鹿
予麋鹿 2021-01-03 11:04

Q1. Why are callback functions used?

Q2. Are callbacks evil? Fun for those who know, for others a nightmare.

Q3. Any alternative to

8条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-03 11:29

    If we in C++ context, consider using (e.g. generalized callbacks).

    The basic behaind idea is that callback (class method) can be of any name and the callback is not required to derive from some class knowned by callback executor.

    The only restriction on callback is input arguments and return value. So this reduces couple to zero ... :)

    UDP:

    Answer of @EffoStaff Effo is an example where callback should be of the particular class (deriving) and have a fix name. All this "restrictions" are absent in context of generalize callbacks.

提交回复
热议问题