【发布时间】:2017-05-05 11:50:09
【问题描述】:
我在 Arduino 环境中的类定义中遇到了继承方法的问题。我有一个基类portal,它继承自类gauge,然后meter 继承自gauge。基类有一个方法的定义,但编译器说它找不到meter::method 的定义。
头文件:
#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..
}
错误信息
错误:没有在中声明的“void Meter::drawContents()”成员函数 类“米”
我问了几个人,但似乎每个人都认为类继承看起来不错 - 这是 Arduino 的事情,还是有一些我不明白的基本原理?感激地收到任何帮助。我担心这是一些愚蠢的错字或; 等的遗漏。
【问题讨论】:
-
声明
void drawContents(void)是portal的一部分,而不是meter... -
错误信息很清楚,在meter类中没有声明
drawContents成员,即使它确实从portal基类继承drawContents成员。
标签: c++ inheritance arduino