View Single Post
  #2   Spotlight this post!  
Unread 02-13-2016, 10:25 PM
duane's Avatar
duane duane is offline
Registered User
FRC #0701 (RoboVikes)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2003
Location: Vacaville
Posts: 90
duane is an unknown quantity at this point
Send a message via AIM to duane
Re: Member function as Task

The technique is to create a static function in your class. The first parameter to your function is this. In the function, dispatch to the member function using the this pointer. This technique is a kind of a thunk.

Code:
class MyClass
{
  private:
    static void sProcessTask(MyClass* self, int someParam);
    void DispatchTask();
    void ProcessTask();
}

void MyClass::sProcessTask(MyClass* self, int someParam)
{
  self.ProcessTask(someParam);
}

void MyClass::DispatchTask()
{
  Task myTask = new Task("MyTask", sProcessTask, this, someParam);
}

void MyClass::ProcessTask(int param) 
{
  // do something on task
}
(Warning: Uncompiled and untested)
__________________
Duane Murphy
Mentor - Software
Vanden Vikings FIRST Team 701
http://www.vandenrobotics.com
Reply With Quote