这是我第一次将我的库功能拆分为多个类。我不确定如何根据类实例化我的对象。即使类在同一个 .h 文件中,我是否需要实例化类对象才能访问这些类方法和变量?我收到第 30 行的错误“不允许不完整类型”。
我的代码:
/*
File: sensor.h
Header file for phSensor Library.
*/
#ifndef SENSOR_H
#define SENSOR_H
#include "mbed.h"
#include "cfExtensions.h"
#include "msExtensions.h"
#include <string>
class phSensor;
class ecSensor;
class tempSensor;
class sensor
{
public:
sensor(); //Default sensor constructor
sensor(cfExtensions &cfExt, msExtensions &msExt);
private:
cfExtensions &_cfExt;
msExtensions &_msExt;
phSensor ph; // Line 30, gets error "incomplete type is not allowed"
ecSensor ec;
tempSensor temp;
string _phCurrentPhValue;
string _phMaxValue;
string _phMinValue;
};
class phSensor
: public sensor
{
public:
phSensor();
void outputPhMaxValue();
private:
float _getCurrentPhValue();
float _getPhMaxValue();
float _getPhMinValue();
void _setPhMaxValue();
void _setPhMinValue();
void _calibratePhSensor();
Ticker getPhMax;
Ticker getPhMin;
};
class ecSensor
: public sensor
{
public:
ecSensor();
};
class tempSensor
: public sensor
{
public:
tempSensor();
};
#endif