Delegue l'execution d'un methode
Bonjour
je voudrais deleguer l'execution d'un methode pour cela je suis partie sur les pointeur de fonction, mais je peche sur la mise en place
header class RButton
Code:
1 2 3 4 5
| class RButton
{
public:
void DoSomething(void (*foo));
} |
Implementation class RButton
Code:
1 2 3 4
| void RButton::DoSomething(void (*foo)){
foo;
}
} |
header class MainScreen
Code:
1 2 3 4 5 6 7
|
class MainScreen :
virtual public Screen
{
public:
void test(void);
} |
Implementation class MainScreen
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| char* MainScreen::DoAction(){
RButton * pressedButton =NULL;
if (_Touch->dataAvailable() == true)
{
int touch_x = _Touch->getX();
int touch_y = _Touch->getY();
for (int i = 0; i < numberOfButton; i++)
{
if ((touch_x >= buttons[i]->Pos_x) and (touch_x <= (buttons[i]->Pos_x + buttons[i]->Width)) and (touch_y >= buttons[i]->Pos_y) and (touch_y <= (buttons[i]->Pos_y + buttons[i]->Height)))
{
pressedButton= buttons[i];
break;
}
}
}
if( pressedButton != NULL){
void (*foo);
foo = &test;
pressedButton->DoSomething(foo); // utilisation du délégué
}
}
void MainScreen::test(void){
Serial.print("test");
}
} |
Bien evidement mon code ne compile pas
Citation:
MainScreen.cpp : test'
MainScreen.cpp : *)()' to 'void*' in assignment
MainScreen.cpp : no return statement in function returning non-void
Comment atteindre mon but
Merci