問題はどこですか?C++ freeRTOSタスク、非静的メンバー関数の無効な使用
void MyClass::task(void *pvParameter){
while(1){
this->update();
}
}
void MyClass::startTask(){
xTaskCreate(this->task, "Task", 2048, NULL, 5, NULL);
}
しかし、私はこれを取得:、私は間違いがどこにあるかをチェックするために有用な任意のドキュメントを見つけることができません
error: invalid use of non-static member function
が、私はそのようなものであるべきだと思う:(C++ 11のSTD ::スレッド)例えば:私の作品
xTaskCreate(&MyClass::task, "Task", 2048, (void*)this, 5, NULL);
ソリューション:
void MyClass::task(){
while(1){
this->update();
}
}
static void MyClass::startTaskImpl(void* _this){
static_cast<MyClass*>(_this)->task();
}
void MyClass::startTask(){
xTaskCreate(this->startTaskImpl, "Task", 2048, this, 5, NULL);
}
'this-> task'' task'は、非静的メンバ関数の場合は有効になりません。 – immibis