Pages: [1]
Author Topic: ofEvent and template  (Read 727 times)
simongeilfus
Brussels, Belgium

Posts: 89

Gravatar


ofEvent and template
« on: February 09, 2010, 03:19:04 PM »

Hello,
I'm trying to use ofEvents with c++ templates but I'm having troubles to find the correct syntax. I would really appreciate if someone could help me resolve this.
I'm using pointers for the event as explained in another post and template for the class that is going to register events, so I can use any class with the addListener method...

Here's the code in my class header:
Code:
ofEvent<InteractiveArea*>   interactiveAreaEvent;

template <class L>
void addListener(L* listener) {
     ofAddListener(interactiveAreaEvent, listener, &(L::interactiveAreaEvent));
}

and in my testApp.cpp:
Code:
void testApp::interactiveAreaEvent(InteractiveArea* sender){
     cout<<"yess"<<endl;
}
void testApp::setup(){
     area->addListener(this);
}

I'm getting this error message :
Quote
error: no matching function for call to 'ofAddListener(ofEvent<InteractiveArea*>&, nanApp*&, void (nanApp::*)(InteractiveArea*))'|
||=== Build finished: 1 errors, 0 warnings ===|

Thanks in advance for any help! I'm kind of lost here!

Simon.
Logged

arturo
Administrator
barcelona

Posts: 2395

Gravatar


WWW
Re: ofEvent and template
« Reply #1 on: February 09, 2010, 04:52:29 PM »

the syntax of the listener method if an event is something like:

Code:
ofEvent<type> event;

is
Code:
void method(type & parameter);

so with the pointer it should be something like:

Code:
void testApp::interactiveAreaEvent(InteractiveArea*& sender){
     cout<<"yess"<<endl;
}

that is kind of complex and also not necesary since you're already receiving a reference you don't really need a pointer so better if you have somthing like:

Code:
ofEvent<InteractiveArea>   interactiveAreaEvent;

template <class L>
void addListener(L* listener) {
     ofAddListener(interactiveAreaEvent, listener, &(L::interactiveAreaEvent));
}

Code:
void testApp::interactiveAreaEvent(InteractiveArea& sender){
     cout<<"yess"<<endl;
}
Logged
simongeilfus
Brussels, Belgium

Posts: 89

Gravatar


Re: ofEvent and template
« Reply #2 on: February 09, 2010, 05:51:30 PM »

Thank you Arturo!
Actually I was using a pointer because "ofEvent<InteractiveArea*> interactiveAreaEvent;" was inside the class "InteractiveArea" but now I've create a separate class for the argument and it's much more clear like that!
Thanks!
Logged

Pages: [1]
 
Jump to:  

Powered by SMF 1.1.15 | SMF © 2011, Simple Machines
kinect

viagra priser