I'm having trouble with inherited methods in a class definitions in the Arduino environment. I have a base class portal which is inherited from by class gauge and then meter inherits from gauge. The base class has a definition for a method, but the compiler says it cant find a definition of meter::method.
Header file:
#ifndef UIelements_h
#define UIelements_h
#include "Arduino.h"
#include "UTFT.h"
#include "URTouch.h"
#include "UTFT_Geometry.h"
class portal
{
public:
UTFT* myDisplay;
int origin[2]={0,0};
int portalSize[2]={10,10};
int BGColor=VGA_BLACK;
int borderSize=1;
int borderColour=VGA_WHITE;
portal();
portal(UTFT* myDisplay);
void draw(void);
void drawContents(void);
private:
bool firstdraw=true;
};
class guage :public portal
{
public:
UTFT_Geometry* myGeometry;
float scaleMin=0.0;
float scaleMax=100.0;
float tick=20;
bool logScale=false;
int scaleColour=VGA_WHITE;
int foreColour=VGA_YELLOW;
float redBegin=80.0;
int redColour=VGA_RED;
float value=0;
float lastValue=0;
guage();
guage(UTFT*,UTFT_Geometry*);
void setNewValue(float);
};
class meter :public guage
{
public:
float startAngle=-40.0;
float endAngle=40.0;
float scaleRadius=80.0;
meter();
meter(UTFT*,UTFT_Geometry*);
void setValueAndDraw(float);
private:
void PointerDraw(float);
};
.cpp
#include "Arduino.h"
#include "UIelements.h"
portal::portal()
{
}
portal::portal(UTFT* UTFT)
{
// constructor: save the passed in method pointers for use in the class
myDisplay=UTFT;
}
void portal::draw(void)
{
// draw the contents
if (firstdraw)
{
// draw background and border
}
else
{
drawContents();
}
}
void portal::drawContents(void)
{
//portal class has no contents to draw, but subclasses will have..
}
...
meter::meter(UTFT* UTFT,UTFT_Geometry* Geometry)
{
// constructor save the passed in method pointers for use in the class
myDisplay=UTFT;
myGeometry=Geometry;
}
void meter::setValueAndDraw(float newValue)
{
setNewValue(newValue);
draw();
}
void meter::drawContents(void)
{
float xcentre=origin[1]+portalsize[1]/2;
float ycentre=origin[2]+portalSize[2]-1;
if (firstdraw=true)
//...more code in here..
}
error message
error: no 'void meter::drawContents()' member function declared in class 'meter'
I've asked a couple of people but everyone seemed to think that the class inheritance looked OK - is this an Arduino thing, or is there something fundamental that I don't understand? Any help gratefully received. I fear that its some silly typo or omission of ; etc.
void drawContents(void)is part ofportal, notmeter...drawContentsmember declared in meter class even though it does inheritdrawContentsmember fromportalbase class.