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
Related
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.
#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.
(Note that the following is an just example based on real code)
Foo.hpp:
#include <thread.h>
#include <iostream>
#include <string>
class Foo
{
private:
std::thread t;
std::string s;
int x;
int y;
public:
Foo();
Foo(std::string s, int x, int y);
void init();
void init(std::string s, int x, int y);
};
Foo.cpp:
#include "Foo.cpp"
Foo::Foo()
{
this->thread = std::thread(static_cast<void (Foo::*)()>(&Foo::init), this);
}
Foo::Foo(std::string s, int x, int y)
{
this->thread = std::thread(static_cast<void (Foo::*)()>(&Foo::init), this, s, x, y);
}
// Foo::init() and Foo::init(std::string s, int x, int y) definitions
This causes g++ to output quite a lot of errors, the most notable of which is likely
no match for call to '(std::_Bind<std::_Mem_fn<void (Foo::*, std::basic_string<char>, int, int)>) ()' (*upCall)();
^
So what am I doing wrong here?
I'm having problems with several C++ programs simply not wanting to run the functions that are defined clearly in a public class above main. I've looked far and wide for answers, but similar problems are the result of not having a scope resolution operator or something similar. As far as I can tell, everything required to call this function is there.
#include <iostream>
#include <stdlib.h>
#include <Windows.h>
using namespace std;
class Box{
public:
Box();
Box(int x, int y);
Box(int x, int y, char type);
Box(char type);
//Accessor functions:
int GetY();
int GetX();
char GetChar();
//Mutator functions:
void SetCoords(int x, int y);
void SetChar(char x);
//Output function:
void printbox(void);
private:
int ycoord;
int xcoord;
char drawing;
};
int main(int argc, char* argv[])
{
Box();
printbox();
return 0;
};
void Box::printbox(void){
//working code
};
What I get instead is error C3861: 'printbox' identifier not found. What's missing that lets the printbox (and other functions like these) run?
printbox is a method therefore you have to call it on an object of type Box. Like this
Box b;
b.printbox();
I recognize that this type of question has been asked, and I looked at those responses but still think I'm missing something. I get this "No matching constructor error", because I don't have a constructor, but that being said, everything that I looked at about constructors said that you need them if you don't already include the variable names inside the class. But I already did that, so do I need a constructor? If I do, what should it look like then? I'm new to C++, taking a class, and this is for an assignment.
Here's my sensor_node.h file with the class declaration:
#ifndef SENSORNODE_H
#define SENSORNODE_H
#include <iostream>
class LOCATION {
float lat, longi, height;
public:
LOCATION (float lat, float longi, float height);
void setx(float xx);
void sety(float yy);
void setz(float zz);
void print();
};
class SensorNode {
char* NodeName;
int NodeID;
LOCATION Node1;
float batt;
int func;
public:
SensorNode(char *n, float x, float y, float z, int i, float ah);
void print();
void setOK(int o);
int getOK();
void setLOC(float longi, float lat, float h);
};
#endif /* defined(__Project_3__sensor_node__) */
And here's my main.cpp with the error (On the line that says "LOCATION"):
#include <iostream>
using namespace std;
#include "sensor_node.h"
int main() {
LOCATION a; SensorNode s1("Pulse",15.9,-30.1,0,157,2.0);
int hold;
Actually, you so have a constructor: LOCATION (float lat, float longi, float height). Since it is the only one, C++ tries to apply it. However, you did not provide any parameters, thus this constructor does not match.
You have a constructor for LOCATION (why the inconsistent capitalisation, incidentally?) that takes three floats, but the line LOCATION a tries to call the default constructor, which you haven't defined.