ofEvent polymorphism?

let’s say I have a class ofxFlashEventArgs which extends ofEventArgs.

is there any way in which I can pass an ofxFlashEventArgs object as if it was an ofEventArgs object?

meaning, for example, returning this event

  
  
ofEvent<ofxFlashEventArgs> testEvent;  
  

from this method

  
  
ofEvent <ofEventArgs> & getEvent(){  
     return testEvent;  
}  
  

another example would be to register a listener with a method that expects an ofEventArgs, but then notify with ofxFlashEventArgs.

  
  
  
class SomeClass {  
  ofEvent <ofxFlashEventArgs> flashEvent;  
}  
// ------------  
void testapp::setup(){  
   ofAddListener(SomeClass->flashEvent, this, &testApp::onFlashEventOccured); // this works  
   ofAddListener(SomeClass->flashEvent, this, &testApp::onAnyEventOccured);   // this doesn't  
}  
  
// this works  
void testAppp::onFlashEventOccured(ofxFlashEventArgs & args){  
   cout << "flash event happened" << endl;  
}  
  
// this doesn't  
void testAppp::onAnyEventOccured(ofEventArgs & args){  
   cout << "any event happened" << endl;  
}  
  

intuitively, it makes sense to me, but I suspect it’s not possible (and both examples throw an error)
am I overlooking something?

thanks,
j

hm, my intuition also says that this should work, ofxFlashEventArgs is an ofxEventArgs, after all, if you inherited from it. the problem is, templates are not polymorphic in that way. see http://stackoverflow.com/questions/2203388/c-templates-polymorphism to learn why.

ah ok, I see.
not sure if I’ll dare to try the proposed solutions. I still find it hard to breath when dealing with templated stuff : )
thanks bilderbuchi,
j

yes polymorphism with templates can get really nasty, you probably don’t want to go that route.

don’t know what you are trying to do but it feels like you are over complicating things a bit : )

perhaps if you explain what you want to do there’s a simpler solution.