第一个c ++库:我不知道在哪里引用和声明我的变量

时间:2012-10-18 04:32:42

标签: c++ class 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

2 个答案:

答案 0 :(得分:1)

我认为你的cfExtensions.cpp文件中应该是void cfExtensions::getPhMinValueFromConfigFile() { }

答案 1 :(得分:1)

在cpp文件中将函数实现更改为

void cfExtensions::getPhMinValueFromConfigFile() {
  // etc ....
}

这里的关键是在函数前面有cfExtensions ::。