Jump to content
  • Advertisement
Sign in to follow this  
Quat

boost::signals2 Annoyance

This topic is 2223 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My Scene has a collection of Objects. Object has a signal called SelectionChanged. For every Object in the Scene, the Scene subscribes to the SelectionChanged signal.

My annoyance is that if an object is removed from the scene, I need to disconnect the subscription. In C#, this would just be something like

obj.SelectionChanged -= OnSelectionChanged;

boost::signals2 does not seem to support this. Do I really have to maintain a collection of boost::signals2::connection for every object so that I can disconnect? There seems to be a lot of extra boilerplate code for signals compared to events in C#.

Share this post


Link to post
Share on other sites
Advertisement
Well in C# you would use delegates, and C++ doesn't have delegates. OnSelectionChanged doesn't have enough meaning to C++ to be able to use it to connect or disconnect to a signal. A slot has to be a combination of the function pointer and the object pointer, plus optional information about additional arguments.

You could create your own delegate class that holds a function object and a connection object, but that wouldn't really save you any work.

You could also have a look at Poco which does have some Event and Delegate classes that are designed to be similar to the C# events and delegates, with a similar syntax. Edited by krippy2k8

Share this post


Link to post
Share on other sites
The C++11 standard library and Boost both essentially have delegates as well (std::function and boost::function), they just don't have an event/signal mechanism that makes use of them with the same type of syntax that C# users are accustomed to.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!