Change from pass-by-value to pass-by-const-ref
The object is copied when put into the list, so there should be no danger of dangling references.
This commit is contained in:
parent
542d607674
commit
ccf4fcae12
@ -4,7 +4,7 @@ using namespace std;
|
||||
using namespace Opm;
|
||||
|
||||
Event&
|
||||
EventSource::add (std::function <void ()> handler) {
|
||||
EventSource::add (const std::function<void ()>& handler) {
|
||||
// add handler to the back of the queue
|
||||
handlers_.push_back (handler);
|
||||
|
||||
|
@ -27,7 +27,7 @@ struct Event {
|
||||
/// \note
|
||||
/// If a handler is added more than once, it will also be called
|
||||
/// more than once.
|
||||
virtual Event& add (std::function <void ()> handler) = 0;
|
||||
virtual Event& add (const std::function <void ()>& handler) = 0;
|
||||
|
||||
/// Convenience routine to add a member function of a class as
|
||||
/// an event handler.
|
||||
@ -83,7 +83,7 @@ struct Event {
|
||||
/// \endcode
|
||||
class EventSource : public Event {
|
||||
public:
|
||||
virtual Event& add (std::function <void ()> handler);
|
||||
virtual Event& add (const std::function <void ()>& handler);
|
||||
virtual void signal ();
|
||||
protected:
|
||||
/// List of actual handlers that will be called
|
||||
|
Loading…
Reference in New Issue
Block a user