第一个C 库:我不确定在哪里参考并声明我的变量
First c++ library: I am not sure where to reference and declare my variables
我目前正在学习如何为我的mbed电子项目编写自己的库。到目前为止,我有两个文件cfextensions.cpp和cfextensions.h文件。我在cfextensions.h构造函数中引用了我的变量,并在我的cfextensions.cpp文件中更改了它们的值;但是,我的MBED C 编译器投掷:标识符" Phmin"是未识别的。我的代码是:
文件:cfextensions.h /* 文件:cfextensions.h
Header file for cfExtensions Library.
*/
#ifndef __cfExtns_H
#define __cfExtns_H
#include "mbed.h"
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//==================================
// Definitions
//==================================
#define CF_FILE_LOCATION "local/settings.cf" // File location local/settings.cf
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//==================================
// cfExtension Class
//==================================
class cfExtensions
{
public:
//---------------------------
// Function Prototypes
//---------------------------
cfExtensions(); // Constructor, Initialisation tasks
void loadConfigFile(); // Loads config file defined in CF_FILE_LOCATION
void checkConfigForFirstStart(); // Check if MBED startup is the very first startup
void getPhMaxValueFromConfigFile(); // Get PH Max value from config file
void getPhMinValueFromConfigFile(); // Get PH Min value from config file
void getKeyAndValue();
//---------------------------
// Variables
//---------------------------
volatile bool pingTicked;
bool linkedWithBaseStation;
char *sbNameKey;
char sbNameValue[BUFSIZ];
char *sbFirstStartKey;
char sbFirstStartValue[BUFSIZ];
char *sbUseBaseStationKey;
char sbUseBaseStationValue[BUFSIZ];
char *sbPhMaxKey;
char sbPhMaxValue[BUFSIZ];
char *sbPhMinKey;
char sbPhMinValue[BUFSIZ];
float phMax;
float phMin;
//---------------------------
// Devices
//---------------------------
};
#endif
文件:cfextensions.cpp
//================================ // Get PH Min Value from CF //================================ void getPhMinValueFromConfigFile() { /* * Get a configuration value. * Then attach the sbNameValue to SensorData json */ if (cfg.getValue(sbPhMinKey, &sbPhMinValue[0], sizeof(sbPhMinValue))) { phMin = atof(sbPhMinValue); } } // End of getPhMinValueFromConfigFile
我认为它应该是cfextensions.cpp文件中的 void cfExtensions::getPhMinValueFromConfigFile() { }
。
在CPP文件中将函数实现更改为
void cfExtensions::getPhMinValueFromConfigFile() {
// etc ....
}
这里的关键是要使cfextensions ::在功能前。
相关文章:
- .cpp和.h文件中的模板专用化声明
- 未在作用域中声明unordered_map
- C++避免重复声明的语法是什么
- 如何确保C++函数在定义之前声明(如override关键字)
- 错误:未在此范围内声明'reverse'
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 为什么在定义函数之前先声明它
- 如何声明特征矩阵,然后通过嵌套循环初始化它
- C++错误消息*成员参考.**初学者*
- #ifdef和未声明的标识符
- 没有显式声明的int[]中的foreach
- 在基于范围的for循环中使用结构化绑定声明
- 为什么参考变量在声明时需要初始化
- 声明模板会员参考另一个类的模板成员数组
- C 常数参考返回算法=作为非函数的声明
- 通过参考或指针声明属性C
- 第一个C 库:我不确定在哪里参考并声明我的变量
- C++11:模板专用化的 constexpr 成员的标准参考需要额外声明
- C++11 gcc:声明中的显式限定?标准参考号
- 使用前声明的历史原因,包括和头/源拆分.需要找到合适的参考资料