Suppose I want to use LiquidCrystal arduino library through a library written by me. I don't want to use LiquidCrystal in the sketch program.
If I call LiquidCrystal on myLib.h like this:
#if(ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#include <inttypes.h>
class LiquidCrystal; // Instead of #include <LiquidCrystal.h>. Booth runs ok
#ifndef MyLib_h
#define MyLib_h
class MyLib{
public:
MyLib();
~MyLib();
private:
LiquidCrystal lcd(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t);
};
#endif
This compiles properly on the sketch program. I initialize LiquidCrystal constructor parameters because this library does not have a constructor without parameters, and if I call lcd like this:
'LiquidCrystal lcd;'
The following error appears: "field ‘lcd’ has incomplete type"
This is the simple skecth program, just to test MyLib:
#include <MyLib.h>
MyLib novaCpu = MyLib();
void setup(){
}
void loop(){
}
The problems appears with MyLib.cpp
If I try this on the constructor cpp, i.e.
...
#include <LiquidCrystal.h>
...
MyLib::MyLib(){
lcd(1,2,3,4,5,6,7,8);
}
...
The following errors are received:
in .cpp: error: invalid use of incomplete type ‘struct LiquidCrystal’
in .h: error: forward declaration of ‘struct LiquidCrystal’
And If I try to write this, instead of previous definition:
...
#include <LiquidCrystal.h>
...
MyLib::MyLib(){
LiquidCrystal lcd(1,2,3,4,5,6,7,8);
}
...
I have an only error in .cpp:
error: variable ‘LiquidCrystal lcd’ has initializer but incomplete type
What can I do? Thanks people