Jump to content
  • Advertisement
Sign in to follow this  
tendifo

event model

This topic is 4144 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

I'm creating a simple event handler thingy in C++ similar to how events are handled in C#. I have three classes: EventSender, EventArgs, and EventHandler. Here's my code for them.
class EventSender
{
public:
    virtual ~EventSender() = 0;
};

class EventArgs
{
public:
    virtual ~EventSender();
}

class EventHandler
{
public:
    virtual void operator()(EventSender& sender, const EventArgs& args) = 0;
};
So any class that might be sent to an event handler extends EventSender. EventArgs represents an empty event args class but can be extended to represent another type of event like EventKeyArgs or something like that. And EventHandler provides a virtual base class for event functors to extend from. Is this a good way to do it? Is my code well formed? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
boost::signal is very, very similar to C# delegates. It should be fairly trivial to wrap it in something to limit use to += and -= akin to a C# event.

Requiring things to inherit from something to use it is (imo) bleh.

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!