From 1a266c24bf33ff7188d549268d8c5fd055194792 Mon Sep 17 00:00:00 2001 From: Sarah Tappon Date: Wed, 6 May 2015 22:59:21 -0700 Subject: [PATCH 1/3] add virtual destructor base classes without virtual destructors risk undefined behavior if their children are deleted through a pointer to base. see https://isocpp.org/wiki/faq/virtual-functions#virtual-dtors --- Adafruit_Sensor.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Adafruit_Sensor.h b/Adafruit_Sensor.h index beb51c8..4e10868 100644 --- a/Adafruit_Sensor.h +++ b/Adafruit_Sensor.h @@ -140,6 +140,7 @@ class Adafruit_Sensor { public: // Constructor(s) void constructor(); + virtual ~Adafruit_Sensor() {} // These must be defined by the subclass virtual void enableAutoRange(bool enabled) {}; From c7b5e92311244679388554aa95f7336567e720c0 Mon Sep 17 00:00:00 2001 From: Sarah Tappon Date: Wed, 6 May 2015 23:14:39 -0700 Subject: [PATCH 2/3] add default constructor in place of constructor() method --- Adafruit_Sensor.cpp | 3 --- Adafruit_Sensor.h | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Adafruit_Sensor.cpp b/Adafruit_Sensor.cpp index 2977b27..ee59b27 100644 --- a/Adafruit_Sensor.cpp +++ b/Adafruit_Sensor.cpp @@ -1,5 +1,2 @@ #include "Adafruit_Sensor.h" #include - -void Adafruit_Sensor::constructor() { -} diff --git a/Adafruit_Sensor.h b/Adafruit_Sensor.h index 4e10868..e6b2c3d 100644 --- a/Adafruit_Sensor.h +++ b/Adafruit_Sensor.h @@ -139,7 +139,7 @@ typedef struct class Adafruit_Sensor { public: // Constructor(s) - void constructor(); + Adafruit_Sensor() {} virtual ~Adafruit_Sensor() {} // These must be defined by the subclass From 73a4e73c87ddda47e82a9d9d2ecf53c1641324db Mon Sep 17 00:00:00 2001 From: Sarah Tappon Date: Wed, 6 May 2015 23:15:56 -0700 Subject: [PATCH 3/3] mark unimplemented virtual functions as abstract --- Adafruit_Sensor.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_Sensor.h b/Adafruit_Sensor.h index e6b2c3d..7742afc 100644 --- a/Adafruit_Sensor.h +++ b/Adafruit_Sensor.h @@ -144,8 +144,8 @@ class Adafruit_Sensor { // These must be defined by the subclass virtual void enableAutoRange(bool enabled) {}; - virtual bool getEvent(sensors_event_t*); - virtual void getSensor(sensor_t*); + virtual bool getEvent(sensors_event_t*) = 0; + virtual void getSensor(sensor_t*) = 0; private: bool _autoRange;