Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom c++ observer is not receiving notifications #33

Closed
rckrdstrgrd opened this issue Jan 31, 2018 · 1 comment
Closed

Custom c++ observer is not receiving notifications #33

rckrdstrgrd opened this issue Jan 31, 2018 · 1 comment

Comments

@rckrdstrgrd
Copy link

rckrdstrgrd commented Jan 31, 2018

When trying to use a custom observer in c++, no notification is received.

The problem seems to be in two places.

  1. 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.

  2. 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.

rckrdstrgrd added a commit to rckrdstrgrd/MWEngine that referenced this issue Jan 31, 2018
@igorski
Copy link
Owner

igorski commented Jan 31, 2018

Great catch! Taken the liberty to take your fixes from your fork into a merge. See #34

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants