需要帮助识别源代码C ++的问题(头,结构,类复杂性) [英] Need Help Identifying Issue with Source Code C++ (Header, Struct, Class complication)

查看:153
本文介绍了需要帮助识别源代码C ++的问题(头,结构,类复杂性)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误:原型为WeatherForecaster :: WeatherForecaster(std ::所有的变量)不匹配任何类在WeatherForecaster
我没有如何避免这一点的想法。我的主要代码与错误btw无关。

error: "prototype for WeatherForecaster::WeatherForecaster(std::all of the variables) does not match any class in WeatherForecaster" I'm out of ideas on how to avoid this. My main code has nothing to do with the error btw.

最近的错误,重新修复。我现在得到错误在主无匹配函数调用WeatherForecast :: WeatherForecast()。在创建变量wf WeatherForecast之后。

MOST RECENT ERROR, THE REST FIXED. I now get the error in main "no matching function to call to WeatherForecast::WeatherForecast()". After I create the variable 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

标题:我犯了这样一个简单的错误,我只是不知道是什么。

Header: I am making such a simple mistake, I'm just not sure what it exactly is.

#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


推荐答案

p>这里是一个更好的优化方法在WeatherForecaster造物主。在WeatherForecaster对象的方法和属性中使用const。我认为结构是多余的,它不是必要的,因为WeatherForecaster对象可以保存数据本身。

Here's a better optimized method in the WeatherForecaster contructor. Use const where ever appropriate in your methods and properties of WeatherForecaster object. I think the struct is redundant and it is not necessary as the WeatherForecaster object can hold the data itself.

#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

这篇关于需要帮助识别源代码C ++的问题(头,结构,类复杂性)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆