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:
Roland Kaufmann 2013-08-26 14:33:23 +02:00
parent 542d607674
commit ccf4fcae12
2 changed files with 3 additions and 3 deletions

View File

@ -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);

View File

@ -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