2016-10-15 4 views
-1

エラー:WeatherForecaster :: WeatherForecasterのプロトタイプ(すべての変数)がWeatherForecasterのどのクラスとも一致しません " 私は出ていますこれを回避する方法のアイデアの私のメインコードはエラーbtwとは関係ありません。ソースコードの問題を特定するためのヘルプが必要

最新のエラー、残りの修正。私は今、メインの "WeatherForecast :: WeatherForecast()"を呼び出すための関数がありません。変数wf WeatherForecastを作成した後。

出典:

#include "WeatherForecaster.h" //header being included 
#include<iostream> 
using namespace std; 

//error comes here 
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 
};//end of block of source code 

ヘッダー:私は、このような単純なミスを作っています、私はそれが正確に何であるかわかりません。コンストラクタこれらのパラメータを取るあなたの宣言(列D、文字列FD、int型H、int型のL、INTハム、INT avgw、文字列avgwd、int型maxw、文字列maxwd、ダブルp)はヘッダにある

#ifndef WEATHERFORECASTER_H 
#define WEATHERFORECASTER_H 

#include <iostream> 
using namespace std; 

//does my code have a problem with how it interacts with this struct? 
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://most recent error ") expected before 'd'" 
    WeatherForecaster(string d, string fd, int h, int l, 
int hum,int avgw, string avgwd, int maxw, string maxwd, double p); 
    ~WeatherForecaster(); 
    void addDayToData(ForecastDay); 
    void printDaysInData(); 
    void printForecastForDay(std::string); 
    void printFourDayForecast(std::string); 
    double calculateTotalPrecipitation(); 
    void printLastDayItRained(); 
    void printLastDayAboveTemperature(int); //argument is the  
    temperature 
    void printTemperatureForecastDifference(std::string); 
    void printPredictedVsActualRainfall(int); 
    std::string getFirstDayInData(); 
    std::string getLastDayInData(); 

protected: 
private: 
    int arrayLength; 
    int index; 
    ForecastDay yearData[984]; 
}; 

#endif // WEATHERFORECASTER_H 
+0

ヘッダーファイルで 'namespace std;'を使用しないでください。そのヘッダーを思いついた人は、これを行うことによってあなたに何の恩恵も与えません。 – PaulMcKenzie

+0

'std :: string'を' #include 'なしで使用しています。それはあなたに 'd'パラメータのエラーを与えるでしょう。 –

答えて

-1

+0

ヘッダーの先頭に構造体がありません – grilam14

+0

私はあなたが私の質問を誤解していると思います。ヘッダファイルに実装された "コンストラクタ"の対応する宣言が表示されませんでした。だから多分それは問題です。 –

+0

ヘッダーを変更できません。私のソースには何か問題があるはずです。私は間違いなくあなたの質問を誤解します – grilam14

-1

"WeatherForecaster(文字列d、文字列fd、int h、int l、intハム、int avgw、文字列avgwd、int maxw、文字列maxwdのプロトタイプを追加する必要があります。 double p) "をWeatherForecasterクラスに追加します。

+0

これはおそらく応答時に眉をひそめますが、私はとても慣れていません:どうすればいいですか? – grilam14

+0

"変更不可"ヘッダーにコンストラクターを追加する必要があります。 –

+0

ヘッダーファイル内のクラスには、WeatherForecaster()という1つのコンストラクターしかありません。これは引数をとりません。ヘッダーに引数を含む行を追加する必要があります。 –

-1

WeatherForecasterコンストラクタでは、より最適化されたメソッドがあります。 WeatherForecasterオブジェクトのメソッドとプロパティで適切な場所にconstを使用します。私は構造体が冗長で、WeatherForecasterオブジェクトはデータ自体を保持できるので必要ではないと思います。

#include "WeatherForecaster.h" 
#include<iostream> 
#include<string> 

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) 
:day(d) 
,forecastDay(fd) 
,highTemp(h) 
,lowTemp(l) 
,humidity(hum) 
,avgWind(avgw) 
,avgWindDir(avgwd) 
,maxWind(maxw) 
,maxWindDir(maxwd) 
,recip(p) 
{ 

} 

WeatherForecaster::~WeatherForecaster(){ 

    //dtor 
}// semi-colon removed fronm your code 
関連する問題