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.
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.
Source:
#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
Where is your declaration of constructor taking these parameter (string d, string fd, int h, int l, int hum,int avgw, string avgwd, int maxw, string maxwd, double p) in the header?
It is exactly as the error message states: you need to add a prototype for "WeatherForecaster(string d, string fd, int h, int l,int hum,int avgw, string avgwd, int maxw, string maxwd, double p)" in your WeatherForecaster class.
Related
https://imgur.com/gallery/pEw8fBs
https://pastebin.com/xvWFHrTU
My errors are posted above..I don't understand what's wrong with this code..I'm trying to construct a book with a date object inside of it. Please help, this is my frist post as well!! :)
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
inline void keep_window_open() { char ch; cin >> ch; }
class Date {
int y, m, d;
public:
Date(int d, int m, int y);
};
class Book {
string title;
string author;
string isbn;
Date date;
public:
Book(string t, string a, string id, Date d);
};
int main() {
Book Charlie("charlie", "gates", "333H", Date(1, 2, 3));
}
Both of your constructors are declared but not defined
class Date {
int y, m, d;
public:
Date(int _d, int _m, int _y) : y(_y), m(_m), d(_d) {} // definition
};
class Book {
string title;
string author;
string isbn;
Date date;
public:
Book(string t, string a, string id, Date d)
: title(t), author(a), isbn(id), data(d) {} // definition
};
Your problem will be solved if you declare a default constructor for Date:
#include <iostream>
#include <string>
using namespace std;
class Date {
int y, m, d;
public:
// Default constructor which will be used in 'Book'
Date() {}
// Don't semicolon here, just two braces required
Date(int d, int m, int y) {}
};
class Book {
string title;
string author;
string isbn;
// Default constructor called here
Date date;
public:
// You can code everything inside the braces now
// NOTE 2: Default constructor called here
Book(string t, string a, string id, Date d) {}
};
int main() {
Book Charlie("charlie", "gates", "333H", Date(1, 2, 3));
return 0;
}
Source File:
#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){
}
Header File:
#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
ERROR: My error happens when I declare try to reach a function in my source file after declaring an instance of the class Weather Function.
ex:
WeatherForecaster wf;
wf.AddDayToData();
//undefined reference to 'WeatherForecaster::AddDaytoData'
I am not entirely sure where the lack of referencing is happening, also I have the header included in main, as well as all other relevant additions.
Edit: I added a function as an example
In your cpp file you need to scope your member function definition
WeatherForecaster::AddDayToData(ForecastDay)
instead of
AddDayToData(ForecastDay)
Also in your call you must pass an argument since it's not optional
#include <iostream>
using namespace std;
void test(float, int);
int main()
{
const int size=11;
float a[size];
test(a, size);
return 0;
}
void test(float a[], int size)
{
[....]
}
it points to test(a, size); but I can't figure out whats wrong(I'm also learning coding and just learned about arrays/confused)
Your function prototype void test(float, int); does not match your function void test(float a[], int size). Change the prototype at the top to void test(float a[], int size); (I like to leave the input variable names in the prototype for consistency, but this is not necessary).
You probably meant to write:
void test(float*, int);
// ...
void test(float* a, int size)
{
[....]
}
when test is called with array argument, array will decay to pointer to its first element - and its size will be lost.
Wrong parameter type for the test forward deceleration.
Try this.
#include <iostream>
using namespace std;
void test(float *, int);
int main()
{
const int size=11;
float a[size];
test(a, size);
return 0;
}
void test(float a[], int size)
{
}
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <cvblob.h>
#include <iostream>
using std::string;
#include <cstdlib>
class ImageProcessing
{
// ImageProcessing* ImgPtr;
private:
IplImage *img0, *img1;
IplImage* ReducImg;
IplImage* ReducImgColor;
CvSize imgSize;
CvPoint C1,C2;
public:
friend class CarVideoHandler;
ImageProcessing(void);
~ImageProcessing(void);
void checkZone(CvTracks::const_iterator ot, double position1, double position2, int **T1,int **T2,int **T3,int **T4, int &numCars, int dire, int p, string type,string dc, string dp);
void checkZoneOneLine(CvTracks::const_iterator ot, double position1, int **T1,int **T2, int &numCars, int dire, int p, string type, int **distance,string dc, string dp);
int CarOrPerson(long area, float wh, CvTracks::const_iterator ot, int *labelTrack[]);
string idTrackCarPerson(IplImage *colourImage1, int *labelTrack[], CvBlobs::const_iterator it, CvTracks::const_iterator ot, int percent, double lin, double position1, double position2, CvFont font, char* wow, int **T1, int **T2, int **T3, int **T4, int &numCars, int &numPersons, int *Xx, int *Xy, int *Yx, int *Yy, int *dire, int n, int m, int p,string dc, string dp);
};
Compiler is throwing error 'CvTrackers' has not been declared when I compile. The same function when I declare it outside the class the compiler was not throwing any error. But when I make it class member the compiler is throwing error. Guys help me to resolve this error.
Ok so I looked through the CVBlobs.h file on Github and the iterator used in the for loops in the relevant struct is CvTracks::iterator. I would suggest trying to remove the const_ and see if that works.
I am trying to compile a library, when running make I get many of the following errors:
error: conflicting declaration ‘int x’
error: ‘x’ has a previous declaration as ‘Text* x’
Here is the code:
.
.
.
class Text;
class Code {
private:
std::vector<std::string> *tokens;
std::vector<std::string> *compounds;
std::vector<std::string> *compound_xml;
std::vector<std::string> *compound_xml_action;
void set_helper(Text *x, int a, int b, int c, std::string field, std::string value);
std::string itoa(int x);
public:
Code();
~Code();
int analyse_code(Text *x, std::string c, int x, int y, int z);
int print(Text *x, std::string c, int x, int y, int z);
int is_class(Text *x, std::string c, int x, int y, int z);
int is_class2(Text *x, std::string c, int x, int y, int z);
int not_class(Text *x, std::string c, int x, int y, int z);
.
.
.
so in analyse_code function\method, should I convert int x to int a or int wtv or is it smth else causing the error?
since the author of the library has used Text* x and int x in many functions, I thought maybe he knows what he's doing and pointers can be int, or am I wrong thinking he knows what he is doing?
Irrelevant: The library is Adso, a Chinese text analysis engine.
You have two parameters named 'x' in declaration like that:
int not_class(Text *x, std::string c, int x, int y, int z);
Name one of them something else. For example:
int not_class(Text *txt, std::string c, int x, int y, int z);
The author was not very good, so beware other errors too.
the problem is not only in analyse_code but in all the private functions. if you have the source code (.c file) I would have check it there also.
anyway you should change the Text *x to anything else such as Text *text