From 495f0ea8c4ddb18c1a932886c88f8eb1483fbf5d Mon Sep 17 00:00:00 2001 From: Mingjie Shen Date: Wed, 24 May 2023 14:28:33 -0400 Subject: [PATCH] Fix invoking virtual functions from constructors Virtual functions should not be invoked from a constructor or destructor of the same class. Confusingly, virtual functions are resolved statically (not dynamically) in constructors and destructors for the same class. The call should be made explicitly static by qualifying it using the scope resolution operator. --- firmware/controllers/trigger/trigger_decoder.cpp | 2 +- firmware/util/math/efi_pid.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index dc7c4a2c6b..e6e735d81f 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -54,7 +54,7 @@ TriggerDecoderBase::TriggerDecoderBase(const char* name) : name(name) { - resetState(); + TriggerDecoderBase::resetState(); } bool TriggerDecoderBase::getShaftSynchronized() { diff --git a/firmware/util/math/efi_pid.cpp b/firmware/util/math/efi_pid.cpp index 997f73659c..ae45806771 100644 --- a/firmware/util/math/efi_pid.cpp +++ b/firmware/util/math/efi_pid.cpp @@ -25,7 +25,7 @@ void Pid::initPidClass(pid_s *parameters) { this->parameters = parameters; resetCounter = 0; - reset(); + Pid::reset(); } bool Pid::isSame(const pid_s *parameters) const { @@ -190,12 +190,12 @@ void Pid::updateITerm(float value) { PidCic::PidCic() { // call our derived reset() - reset(); + PidCic::reset(); } PidCic::PidCic(pid_s *parameters) : Pid(parameters) { // call our derived reset() - reset(); + PidCic::reset(); } void PidCic::reset(void) {