Does using callbacks in C++ increase coupling?

前端 未结 8 1827
予麋鹿
予麋鹿 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

    1. Callbacks are used for example to invoke aynchronous operations, that is, code that runs in a different thread while the caller follows its own way. You need some mechanism to know when the asyncrhonous operation has finished.

    2. Why would them be evil? As with any other programming resource, they are useful when used judiciously. In fact the Windows API and the .NET framework, for example, use callbacks extensively.

    3. Don't know about C++, but in the .NET world, syncronization objects and events are alternatives.

提交回复
热议问题