Class based on LiquidCrystal

It looked so simple, but I cannot create a class that extends class LiquidCrystal with a constructor with no arguments. The class header file should look like this:

class LCDPad : public LiquidCrystal {
  public:
    LCDPad();
    //int getKey(); //to come
};

The arguments should be built into the new constructor, reflecting the LCD keypad shield pins, so that I can instantiate the class like

#include <LCDPad.h>
LCDPad lcd;

error: no matching function for call to 'LiquidCrystal::LiquidCrystal()'

Is this really impossible to achieve?

Your answer is here:

http://www.learncpp.com/cpp-tutorial/114-constructors-and-initialization-of-derived-classes/

Regards,
Ray L.

You have to pass through the arguments to the constructor, as I have done with an LCD class:

class sevenSegment : public HT1621
{
  public:
    sevenSegment(byte selectPin, byte rwPin, byte dataPin);
//..........

}; // end class

// then the implementation...

// constructor:
sevenSegment::sevenSegment(byte selectPin, byte rwPin, byte dataPin)
  : HT1621(selectPin, rwPin, dataPin) {}

Okay, maybe not what you wanted exactly. But it's a start. Unless I misunderstand you, you wish to internalize the constructor parameters. In my case, the result of that would be losing the ability to define multiple displays. I'm not sure about yours. But you might want to reconsider... although it could be a (replace the?) default constructor...

aarg:
You have to pass through the arguments to the constructor, as I have done with an LCD class:

class sevenSegment : public HT1621

{
  public:
    sevenSegment(byte selectPin, byte rwPin, byte dataPin);
//..........

}; // end class

// then the implementation...

// constructor:
sevenSegment::sevenSegment(byte selectPin, byte rwPin, byte dataPin)
  : HT1621(selectPin, rwPin, dataPin) {}



Okay, maybe not what you wanted exactly. But it's a start.

But not the best way to handle it. See the link I posted...

Regards,
Ray L.

aarg:
You have to pass through the arguments to the constructor, as I have done with an LCD class:

class sevenSegment : public HT1621

{
 public:
   sevenSegment(byte selectPin, byte rwPin, byte dataPin);
//..........

}; // end class

// then the implementation...

// constructor:
sevenSegment::sevenSegment(byte selectPin, byte rwPin, byte dataPin)
 : HT1621(selectPin, rwPin, dataPin) {}

Thanks, I didn't remember the colon trick :slight_smile:

Okay, maybe not what you wanted exactly. But it's a start. Unless I misunderstand you, you wish to internalize the constructor parameters. In my case, the result of that would be losing the ability to define multiple displays.

As I'm using a shield, that can be stacked only once (on top), only one instance is ever required.

RayLivingston:
But not the best way to handle it. See the link I posted...

I've moved everything into the class declaration, now it works as expected.
But I'm not sure what you mean with "best way". Which way would you prefer?

And another question:
Since I want a singleton, can I move the instance variable also into the header file?
How do I prevent multiple variables then?
I'd guess that then I have to duplicate the declaration in the related cpp file, so that the variable is allocated in that module?