gogolf0401
gogolf0401

Reputation: 93

I am getting an undefined reference to vtable error

Here is my class which is in a header.

class AlarmPatterns
{
public:
   AlarmPatterns() {}

   virtual~AlarmPatterns();

   //alarm patterns
   enum class PATTERN_TYPES_E
   {
      BEEP_MODE,        //150
      IGN_BULBCHECK,    //160
      LOW_PRIO_REMIND,  //170
      DM1_RED,          //200
      HP_ALERT_5,       //210
      HP_ALERT_4,       //220
      HP_ALERT_3,       //230
      HP_ALERT_2,       //240
      HP_ALERT_1,       //250
      NUM_PATTERNS
   };

   static bool LoadPatternData(AP_S & pattern, const uint8_t id);

   static const AP_S Patterns[];
};

AP_S is a typedef struct within the same namespace but outside the class

This is a base class since we aren't deriving from any other classes

In my test.cpp file I have:

AlarmPatterns * TestPattern;

void setup()
{
   TestPattern = new AlarmPatterns();
}

Commenting TestPattern = new AlarmPatterns(); results in no errors

Here is the error

undefined reference to `vtable for Dragonfly::Alarm::AlarmPatterns'

Since there is no way I am missing any virtual functions from any base classes, I don't see how I am getting this error.

Upvotes: 2

Views: 239

Answers (2)

Michael Anderson
Michael Anderson

Reputation: 73480

This happens when you're missing the definition of the first virtual function.

In your case its ~AlarmPatterns() .. add an implementation of that and all should just work.

Upvotes: 0

6502
6502

Reputation: 114461

You are forward declaring a destructor, but you're not providing a definition.

If you want an empty destructor because this is meant to be a base class with other virtual methods just declare an empty destructor:

virtual ~AlarmPatterns() {} // Note the braces

Upvotes: 2

Related Questions