Event in C++

M

moonlight

Is event part of C++ language standard? How to implement event in C++? Any
advices are welcome!
 
A

Alf P. Steinbach

Is event part of C++ language standard?
No.



How to implement event in C++?

There is wide range of possibilities, from the simplest to very
complex.

Simplest case: a single event, single event receiver, event receiver
lifetime extends before and after lifetime of event source.

In this case, define an interface with a virtual method onXxx().
Implement this interface in the event receiver class. Pass this
interface to the constructor of the event source object. The
event source stores a reference to the event interface and calls
onXxx() as appropriate.

More complex cases give correspondingly more complex solutions.

The main problem in such cases is lifetime control, since an
event receiver then typically has a reference to the event source,
which in turn has a reference back to the receiver, which breaks
the assumptions of most smart-pointer classes.



Any advices are welcome!

Specify what you think you need events _for_. Perhaps event handling
isn't the best or simplest solution.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,137
Messages
2,570,800
Members
47,348
Latest member
Mikientp

Latest Threads

Top