错误:对class :: method的未定义引用(main,头文件,源代码)

时间:2016-10-15 06:31:30

标签: c++

源文件:

#include "WeatherForecaster.h"
#include <iostream>
using namespace std;


WeatherForecaster::WeatherForecaster(string d, string fd, int h, int l, int hum,int avgw, string avgwd, int maxw, string maxwd, double p){

string day=d;
string forecastDay=fd;
int highTemp=h;
int lowTemp =l;
int humidity=hum;
int avgWind= avgw;
string avgWindDir=avgwd;
int maxWind=maxw;
string maxWindDir= maxwd;
double recip=p;
 }
 WeatherForecaster::WeatherForecaster(){

 //dtor
 }
 void AddDaytoData(ForecastDay){
 }

标题文件:

 #ifndef WEATHERFORECASTER_H
#define WEATHERFORECASTER_H

#include <iostream>

using namespace std;

 struct ForecastDay{
 std::string day;
 std::string forecastDay;
 int highTemp;
 int lowTemp;
 int humidity;
 int avgWind;
 std::string avgWindDir;
 int maxWind;
 std::string maxWindDir;
 double precip;

};

class WeatherForecaster

{

 public:

    WeatherForecaster(string, string, int, int,
    int,int, string, int, string , double );
    WeatherForecaster();
    void addDayToData(ForecastDay);
    void printDaysInData(); //prints the unique dates in the data
    void printForecastForDay(std::string);
    void printFourDayForecast(std::string);
    double calculateTotalPrecipitation();
    void printLastDayItRained();
    void printLastDayAboveTemperature(int); 
    void printTemperatureForecastDifference(std::string);
    void printPredictedVsActualRainfall(int); 
    std::string getFirstDayInData();
    std::string getLastDayInData();

 protected:
 private:
    int arrayLength;
    int index;
    ForecastDay yearData[984]; //data for each day
};

#endif // WEATHERFORECASTER_H

错误:我声明尝试在声明类别天气函数的实例后到达源文件中的函数时发生错误。

例如:

 WeatherForecaster wf;
 wf.AddDayToData();
//undefined reference to 'WeatherForecaster::AddDaytoData' 

我不完全确定缺少引用的位置,我也在主要内容中包含了标题,以及所有其他相关的附加内容。

编辑:我添加了一个函数作为示例

1 个答案:

答案 0 :(得分:0)

在cpp文件中,您需要确定成员函数定义的范围

WeatherForecaster::AddDayToData(ForecastDay) 

而不是

AddDayToData(ForecastDay)

同样在你的电话中你必须传递一个参数,因为它不是可选的