You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to use a custom observer in c++, no notification is received.
The problem seems to be in two places.
It's not possible to override the observer functions handleNotification(int aNotificationType) and handleNotification(int aNotificationType, int aValue) because these are not declared as virtual in observer.h. When these functions later are called the parent functions will be invoked, the virtual declaration is needed to achieve late binding of these functions.
The vector list of observers in notifier.cpp will never be filled. This line: std::vector<Observer*> observers = it->second;
will create a copy of the observer vector, and subsequent calls to observers.push_back( aObserver ); will be executed on the copy and not the vector in the map. Calling push_back directly on it->second will work.
The text was updated successfully, but these errors were encountered:
When trying to use a custom observer in c++, no notification is received.
The problem seems to be in two places.
It's not possible to override the observer functions
handleNotification(int aNotificationType)
andhandleNotification(int aNotificationType, int aValue)
because these are not declared asvirtual
inobserver.h
. When these functions later are called the parent functions will be invoked, thevirtual
declaration is needed to achieve late binding of these functions.The vector list of observers in notifier.cpp will never be filled. This line:
std::vector<Observer*> observers = it->second;
will create a copy of the observer vector, and subsequent calls to
observers.push_back( aObserver );
will be executed on the copy and not the vector in the map. Callingpush_back
directly onit->second
will work.The text was updated successfully, but these errors were encountered: