当前位置: 动力学知识库 > 问答 > 编程问答 >

sdl - How do you implement Signals and Events in C++?

问题描述:

I am making a Gui Library on top of SDL using C++. (Don't ask me why, I am just doing it to gain some knowledge out of practice in order to understand how Gui libraries are made.) And I want to make a signal connection system like gtk+ or wxWidgets...

 g_signal_connect(mybutton,"clicked",gtk_main_quit); //Gtk+

EVT_MENU(wxID_EXIT,OnQuit); //WxWidgets

I understand I can do this using function pointers. But how do I add the functions to the main loop?

Or Is there a better way to do this?

网友答案:

The simplest way is borrowing it from a library, for example boost::signal or boost::signal2. The next best thing is implementing your own but borrowing most of the features from libraries like boost::bind (to enable the connections) or using C++0x features that will simplify the generic connection of clients (std::function / boost::function).

I would recommend that you use boost and their signals2 library, as there are many things that you can do wrong and are already solved there.

分享给朋友:
您可能感兴趣的文章:
随机阅读: