View Single Post
  #4   Spotlight this post!  
Unread 02-14-2016, 11:13 AM
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 298
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: Member function as Task

You can use a member function but you'll have to pass an instance to Task. I've looked in the Task source and it should work, since it forwards all of its arguments to thread. Thread internally detects if you gave a member function pointer and uses the first argument as the instance to call the function from.
Code:
class MyClass
{
  private:
    void DispatchTask();
    void ProcessTask(int param);
}

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

void MyClass::ProcessTask(int param) 
{
  // do something on task
}
&MyClass::SomeFunction is a pointer to a member function.

Last edited by euhlmann : 02-14-2016 at 11:15 AM.
Reply With Quote