I have the following errors trying to use a TFT library function inside my library. My library uses the pointer to an instance of the TFT library in the constructor, as well described there:
Basic C++ programming, how to pass constructor argument into class?
The errors are:
error: invalid use of incomplete type 'class TFT'
_TFTscreen->background(0, 0, 0);
error: forward declaration of 'class TFT'
class TFT;
MESmenu.h:
#ifndef _MESMENU_H_
#define _MESMENU_H_
#include <SPI.h>
#include <SD.h>
class TFT;
class MESmenu{
public:
MESmenu(TFT* pTFT) : _TFTscreen(pTFT) {};
void start();
void execute();
private:
TFT* _TFTscreen;
};
#endif
MESmenu.cpp:
#include "Arduino.h"
#include "MESmenu.h"
void MESmenu::start(){
_TFTscreen->background(0, 0, 0);
_TFTscreen->text("starting menu...", 0, 0);
//...
}
void MESmenu::execute(){
//some code...
}
The Arduino sketch is:
#include <SPI.h>
#include <SD.h>
#include <TFT.h> // Arduino LCD library
#include <MESmenu.h> // my library
// --------- TFT LCD ---------
// pin definition for the due
#define sd_cs 7
#define lcd_cs 10
#define dc 9
#define rst 8
TFT TFTscreen = TFT(lcd_cs, dc, rst);
// MES menu class
MESmenu *mainMenu = new MESmenu(&TFTscreen);
void setup() {
// initialize TFT
TFTscreen.begin();
TFTscreen.background(0, 0, 0);
// set the stroke color to white
TFTscreen.stroke(255,255,255);
TFTscreen.fill(255,255,255);
TFTscreen.setTextSize(2);
TFTscreen.text("TEST", 0, 0);
// Start menu
mainMenu->start();
}
void loop () {
mainMenu->execute();
}
The problem is related to the function:
_TFTscreen->background(0, 0, 0);
inside the MESmenu::start() in the .cpp file.
UPDATE:
As suggested by frarugi87 I've updated the question with the details of .h and .cpp files. Those file are in the Arduino\libraries\MESmenu folder.
I try to change
class TFT;
with
#include <TFT.h>
and removed the #include from the main arduino sketch.
This leads to the following errors:
libraries\MESmenu\MESmenu.cpp.o: In function `Adafruit_GFX::image(PImage&, unsigned int, unsigned int)':
D:\Software\arduino-1.6.7\libraries\TFT\src/utility/Adafruit_GFX.h:231: multiple definition of `Adafruit_GFX::image(PImage&, unsigned int, unsigned int)'
sketch\test_MESmenu_lib.ino.cpp.o:D:\Software\arduino-1.6.7\libraries\TFT\src/utility/Adafruit_GFX.h:231: first defined here
libraries\MESmenu\MESmenu.cpp.o: In function `Adafruit_GFX::image(PImage&, unsigned int, unsigned int)':
D:\Software\arduino-1.6.7\libraries\TFT\src/utility/Adafruit_GFX.h:231: multiple definition of `PImage::read16(SDLib::File)'
sketch\test_MESmenu_lib.ino.cpp.o:D:\Software\arduino-1.6.7\libraries\TFT\src/utility/PImage.h:17: first defined here
libraries\MESmenu\MESmenu.cpp.o: In function `Adafruit_GFX::image(PImage&, unsigned int, unsigned int)':
D:\Software\arduino-1.6.7\libraries\TFT\src/utility/Adafruit_GFX.h:231: multiple definition of `PImage::read32(SDLib::File)'
sketch\test_MESmenu_lib.ino.cpp.o:D:\Software\arduino-1.6.7\libraries\TFT\src/utility/PImage.h:17: first defined here
libraries\MESmenu\MESmenu.cpp.o: In function `Adafruit_GFX::image(PImage&, unsigned int, unsigned int)':
D:\Software\arduino-1.6.7\libraries\TFT\src/utility/Adafruit_GFX.h:231: multiple definition of `PImage::loadImage(char const*)'
sketch\test_MESmenu_lib.ino.cpp.o:D:\Software\arduino-1.6.7\libraries\TFT\src/utility/PImage.h:17: first defined here