arkhipenko / TaskScheduler

Cooperative multitasking for Arduino, ESPx, STM32, nRF and other microcontrollers
http://playground.arduino.cc/Code/TaskScheduler
BSD 3-Clause "New" or "Revised" License
1.22k stars 224 forks source link

Virtual destructor on bare metal #124

Closed kevinpt closed 3 years ago

kevinpt commented 3 years ago

The switch to a virtual destructor for the Task class in #86 is problematic outside the Arduino environment. The current code forces the creation of a vtable for Task and needs operator delete to exist. There is no need for a virtual destructor if none of the other methods are virtual. Composition can achieve the same result as subclassing. It should be conditional on the definition of _TASK_OO_CALLBACKS.

TD-er commented 3 years ago

You do also need a virtual destructor if another class inherits from your class. For example if you have a pointer to the base class and destruct it, you really need a virtual destructor. This is not depending on the presence of virtual functions.

So I really wonder in what use case this causes an issue.

arkhipenko commented 3 years ago

@kevinpt: I have reviewed the interface and I am not sure that any of the other methods are actually meant to be virtual - since they represent fundamental task behaviors not meant to be changed. If you disagree - please provide a use case proving otherwise. However - a virtual destructor is indeed needed to properly destroy inherited objects.