Why is event handling in native Visual C++ deprecated?

强颜欢笑 提交于 2019-12-24 01:09:42

问题


http://msdn.microsoft.com/en-us/library/ee2k0a7d.aspx

Event handling is also supported for native C++ classes (C++ classes that do not implement COM objects), however, that support is deprecated and will be removed in a future release.

Anyone knows why? Couldn't find any explanation for this statement.


回答1:


  1. It's totally non-standard kludge that probably has very little actual users. And I mean non-stndard kludge even in WinNT and Microsoft-private world.

  2. COM has much richer repertoire for event-like mechanisms and also allow fully multi-threaded code these days

  3. This one is lethal - that functionality is doing implicit locking (probably our grandpa's idea of "synchonized" before templates and widespread safe use of normal critical sections). That makes it more dangerous than COM's single apartment, ahem, thing :-) As in it can give you a deadlock out of nowhere (happened to Java's synchronized methods as well - nothing special :-)

  4. Everyone and their dogs know how to use normal multi-threading and at least critical sections with smart pointers these days, so besides being dangerous, that thing is also irrelevant.




回答2:


I'd hazard a guess, and it is just that, that similar functionality can be achieved by a signal/slots type library in a more more portable/standard C++ (with templates) fashion rather than requiring compiler support by MS.




回答3:


I'd hazard a guess that they would want you to do it all the .Net way now.




回答4:


Have a look at Boost::Signals2

(This is the successor of Boost Signals, which is no longer maintained)



来源:https://stackoverflow.com/questions/2295639/why-is-event-handling-in-native-visual-c-deprecated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!