ofEvents not working if object is in std::vector

I have a class that registers itself to receive ofEvent notifications like update, draw and also mousePressed, released, etc. If I use the object alone - everything works. As soon as I use a std::vector with this kind of objects inside, events do not work. If I use an array of the object type - events work again.

Has someone experienced this and found a fix/workaround? Some other workaround than calling update, draw and mouse functions for each object with a for loop?

I also made a simple openFrameworks example that shows what I mean. Here: https://github.com/kr15h/vectorEvents

OK, I solved this by obtaining the knowledge to operate with the “heap” concept. Simply put use myObject obj = new myObject(); and then add the object to your vector of object pointers:

myObject obj = new myObject();
vector<myObject*> myVector;

Don’t forget to delete the object before you do myVector.pop_back().

delete myVector.back();

Updated code of the example still on GitHub: https://github.com/kr15h/vectorEvents