Hello, been having an error with Pros Tasks and it’s driving me insane. I’m trying to use tasks but it keeps throwing me an error that says “no matching constructor for initialization of ‘pros::Task’”. Please help.
Try this…
void myFunction(void * param) {}
pros::task_t myTask = pros::c::task_create(myFunction, (void*)"PROS", TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "MyTask");
Also if you still get an error can you share your code.
Try what @Codec suggested and/or share your code. Perhaps you’re not providing the arguments in the correct order to the Task constructor. C++ errors can sometimes be cryptic if you’re not used to staring at them
Ah that fixed it, pros::Task is used to create a c++ task given an already defined c task.
Like such:
void function(void* param) {}
pros::task_t task = pros::c::task_create(function, (void*)"PROS", TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "Task Name");
pros::Task cpptask (task);
Well, that’s one (but roundabout) way to do it. pros::Task
does have a constructor that uses task_t
as a parameter, but that is not the intended use.
You can create the C++ object directly without needing task_t
.
void myFunction(void*) {}
pros::Task task(myFunction);
will work.
Likely your problems before was that you were not doing a void(void*)
, you just had a void()
.
If you want to give the task more parameters, you can do
void myFunction(void*) {}
pros::Task task(myFunction, nullptr, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "task");
Oh wait, you’re right, goddamn i suck at programming, thanks.