Inheritance Problems

I know there is probably something stupid that i'm missing, but I just can't seem to figure this one out.

Error:
In file included from impact_v1_1.ino:3:
keypad_4x4.h:8: error: expected class-name before '{' token

impact_v1_1.ino:

#include <LiquidCrystal.h>
#include "keypad_4x4.h"

void setup()
{
  keypad_4x4 myKeypad;
  myKeypad.keyInput();
}

void loop()
{

}

keypad_4x4.h

#ifndef KEYPAD_4X4_H
#define KEYPAD_4X4_H

#include <WProgram.h>
#include <Keypad.h>

class keypad_4x4 : public Keypad
{
  public:
    keypad_4x4();
    ~keypad_4x4();
    static const int rowPins[4];
    static const int colPins[4];
    void keyInput();
  
  private:
    static const char keys[4][4];
};

#endif

keypad4x4.cpp

#include "keypad_4x4.h"

keypad_4x4::keypad_4x4()
{
  Keypad(makeKeymap(keys), rowPins, colPins, 4, 4)
}

char const keypad_4x4::keys[4][4] =
(
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'#', '0', '*', 'D'}
);

byte const keypad_4x4::rowPins[4] = {9, 8, 7, 6};
byte const keypad_4x4::colPins[4] = {13, 12, 11, 10};

keypad_4x4::keyInput()
{
    LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
    lcd.begin(16, 2);
    lcd.print("keypad run");
    delay(5000);
}

Thanks in advance.

What version of the IDE? If post 1.0, why are you including WProgram.h?

PaulS:
What version of the IDE? If post 1.0, why are you including WProgram.h?

I'm using 1.0.5. I thought I had to include it in all .h files to compile correctly.

Looks like you're missing a semicolon in the keypad4x4 constructor:
Keypad(makeKeymap(keys), rowPins, colPins, 4, 4)

I thought I had to include it in all .h files to compile correctly.

For 0023 and earlier, yes. For 1.0+, you need to include Arduino.h.

ralphd:
Looks like you're missing a semicolon in the keypad4x4 constructor:
Keypad(makeKeymap(keys), rowPins, colPins, 4, 4)

Thanks for the head's up, but I actually commented out that line trying to eliminate as many possibilities for error as possible.

PaulS:

I thought I had to include it in all .h files to compile correctly.

For 0023 and earlier, yes. For 1.0+, you need to include Arduino.h.

This is good to know, however, after doing some digging in the Keypad library, "Arduino.h" (or "WProgram.h") is automatically included from "Keypad.h".

Thanks for the head's up, but I actually commented out that line trying to eliminate as many possibilities for error as possible.

So, now you have some code and possibly some errors. If you care to share them, we might be able to help.

Edit: By the way, including a header file, like Keypad.h, in a library but not in the sketch never has worked, and probably never will work.

PaulS:

Thanks for the head's up, but I actually commented out that line trying to eliminate as many possibilities for error as possible.

So, now you have some code and possibly some errors. If you care to share them, we might be able to help.

Edit: By the way, including a header file, like Keypad.h, in a library but not in the sketch never has worked, and probably never will work.

From the original post: :wink:

fatirishman53:
Error:
In file included from impact_v1_1.ino:3:
keypad_4x4.h:8: error: expected class-name before '{' token

Thanks! I think including Keypad.h in the sketch fixed the problem... now I have some other errors to fix :). Is there a reason why you have to do this? It seems redundant to me.

Is there a reason why you have to do this?

No reason. It's just company policy.

Of course there is a reason. It's because it is necessary. Now, the question might reasonably be "why?", and the answer involves how the IDE determines what to compile. It converts your .ino file to a .cpp file, adding the function prototypes that you left out (if any), and writing that .cpp file to a different build directory. It also copies a bunch of other stuff to that build directory, based on the include statements in the sketch (but not based on include statements in other files). Without Keymap.h in the sketch, the Keymap library files are not copied. When the build process tries, then, to compile your library, it can't find Keymap.h because it is not in the build directory.

PaulS:

Is there a reason why you have to do this?

No reason. It's just company policy.

Of course there is a reason. It's because it is necessary. Now, the question might reasonably be "why?", and the answer involves how the IDE determines what to compile. It converts your .ino file to a .cpp file, adding the function prototypes that you left out (if any), and writing that .cpp file to a different build directory. It also copies a bunch of other stuff to that build directory, based on the include statements in the sketch (but not based on include statements in other files). Without Keymap.h in the sketch, the Keymap library files are not copied. When the build process tries, then, to compile your library, it can't find Keymap.h because it is not in the build directory.

Thanks for the info!