Hello everyone: I am an experienced C # programmer trying to do some work in C ++, and I'm not sure of the correct way to do this:
I am creating a class that should notify the consumer class that something has happened.
If I wrote this in C #, I would define an event in my class.
There are no events in C ++, so I'm trying to figure out how to do it right. I thought of callback functions, but how do I handle the case when I want to execute a member function (rather than a static function).
More specifically, I really need to do this in order to handle the event, but have access to the state of the participant in the instance of the object that processes the event.
I look at std :: tr1: function, but I am having problems with its operation.
I don't think anyone would like to translate the following C # example example into a good / good C ++ example (I need ANSI C ++)? (remember that I have almost no C ++ experience - do not assume that I know any long-established C ++ conventions - I do not;);
Simple C # console application (works on my machine):
using System; namespace ConsoleApplication1 { public class EventSource { public event EventHandler<EchoEventArgs> EchoEvent; public void RaiseEvent(int echoId) { var echoEvent = this.EchoEvent; if (echoEvent != null) echoEvent(this, new EchoEventArgs() {EchoId = echoId}); } } public class EchoEventArgs : EventArgs { public int EchoId { get; set; } } public class EventConsumer { public int Id { get; set; } public EventConsumer(EventSource source) { source.EchoEvent += OnEcho; } private void OnEcho(object sender, EchoEventArgs args) {
source share