-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
non virtual destructor #21
Comments
Adding a virtual destructor would waste resources, and there is no reason to have one, as the MooreMachine class (and derived classes) is NOT intended to be deleted through a pointer to it. Or am I missing something? |
If you have already a virtual method which resources are you wasting? |
At least a vtable entry, not sure what else. Building without virtual destructor:
with virtual destructor
|
Building with `-Wnon-virtual-dtor` prints warnings for each `tinyfsm::Fsm` class: > warning: 'class Elevator' has virtual functions and accessible > non-virtual destructor [-Wnon-virtual-dtor] Adding a virtual destructor would waste resources (at least one vtable entry). There is no reason to have a one, as the MooreMachine class (and derived classes) is NOT intended to be deleted through a pointer to it. Building `examples/api/moore_machine.cpp` results in: - without virtual destructor: # size -B -d moore_machine text data bss dec hex filename 3277 768 584 4629 1215 moore_machine - with virtual destructor in `MooreMachine` # size -B -d moore_machine text data bss dec hex filename 3662 808 600 5070 13ce moore_machine Ref: #21
Hi,
I like you take on a simple state machine. When building with -Wnon-virtual-dtor you got some warning. I would add
virtual ~MooreMachine() noexcept = default;
to the MooreMachine template.
There is some reason I am missing why it is not there?
The text was updated successfully, but these errors were encountered: