Inheritance: error in calling the constructor of the base class?

I want to write a library for the RGBDigit shield (http://rgbdigit.com/), which essentially is an Adafruit Neopixel strip, packed as a 7 segment display. The shield also has a DS3231 clock and an IR receiver.

So my plan was to make a class RGBDigit, which inherits from the Adafruit_NeoPixel class and add private members DS3231 and IRrecv.

This is my RGBDigit.h:

#ifndef RGBDigit_h
#define RGBDigit_h

#include <Arduino.h>
#include "Wire.h"
#include "../Adafruit_NeoPixel/Adafruit_NeoPixel.h"
#include "../IRremote/IRremote.h"
#include "../DS3231/DS3231.h"

class RGBDigit : public Adafruit_NeoPixel {
  public:
    RGBDigit(int nDigits);
    ~RGBDigit();
  private:
    int _nDigits;
    DS3231 _clock;
    IRrecv* _ir;
};

#endif

This is RGBDigit.cpp:

#include "RGBDigit.h"


RGBDigit::RGBDigit(int nDigits)
  : Adafruit_NeoPixel(8 * nDigits, 12, NEO_GRB + NEO_KHZ800),
  _nDigits(nDigits)
{
  _ir = new IRrecv(10);
  _ir->enableIRIn(); // Start the receiver
  Adafruit_NeoPixel::begin();
}

RGBDigit::~RGBDigit()
{
  delete _ir;
}

And this is my Arduino sketch:

#include <Wire.h>
#include <RGBDigit.h>

RGBDigit display = RGBDigit(4);

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

I get al lot of "undefined reference" errors:

RGBDigit/RGBDigit.cpp.o: In function `RGBDigit::RGBDigit(int)':
/home/ralph/Arduino/libraries/RGBDigit/RGBDigit.cpp:23: undefined reference to `Adafruit_NeoPixel::Adafruit_NeoPixel(unsigned int, unsigned char, unsigned char)'
/home/ralph/Arduino/libraries/RGBDigit/RGBDigit.cpp:23: undefined reference to `DS3231::DS3231()'
/home/ralph/Arduino/libraries/RGBDigit/RGBDigit.cpp:25: undefined reference to `IRrecv::IRrecv(int)'
/home/ralph/Arduino/libraries/RGBDigit/RGBDigit.cpp:26: undefined reference to `IRrecv::enableIRIn()'
/home/ralph/Arduino/libraries/RGBDigit/RGBDigit.cpp:27: undefined reference to `Adafruit_NeoPixel::begin()'
RGBDigit/RGBDigit.cpp.o: In function `RGBDigit::~RGBDigit()':
/home/ralph/Arduino/libraries/RGBDigit/RGBDigit.cpp:30: undefined reference to `Adafruit_NeoPixel::~Adafruit_NeoPixel()'
collect2: error: ld returned 1 exit status

But I don' t understand why. What am I doing wrong?

RGBDigit.h

#include "../Adafruit_NeoPixel/Adafruit_NeoPixel.h"
#include "../IRremote/IRremote.h"
#include "../DS3231/DS3231.h"

Change these to

#include <Adafruit_NeoPixel.h>
#include <IRremote.h>
#include <DS3231.h>

and add them to your sketch, too.

Thank you very much; it works now!

But isn't it a bad thing that someone who wants to use my RGBDigit library, also needs to know which other classes and libraries are used by RGBDigit?

But isn't it a bad thing that someone who wants to use my RGBDigit library, also needs to know which other classes and libraries are used by RGBDigit?

No, that is NOT a bad thing.

I hate when I find some code that looks useful, so I download it and it fails because it has some previously undefined dependency on some other code which has some previously undefined dependency on some other code which has some previously undefined dependency on some other code which has some previously undefined dependency on some other code...

MUCH better to know UP FRONT.

What if the code upon which the code which depends on the code depends (and so on...) is packaged together with the code in the library itself?

Shouldn't there be a way to include multiple files which I have developed, in a library file, in such a way that there is only one include file for the user to use?

It seems reasonable to me that you could have nested includes for files which you guarantee will be present in the library folder, by virtue of their inclusion in the zip file or other distribution. Isn't that the way things are in a "normal" compiling environment?

I can see the reason for explicitly including other libraries, but that seems different to me.

I do have a specific reason for asking, which is that I am now at the point where some of my projects share drivers and so on. I'd like to start encapsulating things more. I haven't tried implementing it yet, but the implications of this thread scare me.

I haven't tried implementing it yet, but the implications of this thread scare me.

Don't be scared until you try.

Personally, I don't like the idea of hiding the use of nested libraries. On the other hand, the IDE has a function that can add the include files needed for a particular library in one step, and that often results in several new #include statements being added. I haven't used that capability in ages, and I have no clue how it works, but it does seem possible to make the tool know that to use library A, you also need to include B.h, C.h and D.h.

That would be fine. Thanks, I will investigate.