having this problem while running my main.cpp. there are a bunch of class .h and .cpp files and for some reason i just get this error.
In file included from /home/ubuntu/workspace/cs1440-hw2/Analyzer.h:8:0,
from /home/ubuntu/workspace/cs1440-hw2/Station.h:7,
from /home/ubuntu/workspace/cs1440-hw2/Day.h:6,
from /home/ubuntu/workspace/cs1440-hw2/main.cpp:7:
/home/ubuntu/workspace/cs1440-hw2/Region.h:12:3: error: ‘Station’ does not name a type
Station* _stations[MAX_STATION_COUNT];
this was not code written by me but im trying to reorganize it into seperate files but when i finished that and tried to run it i kept getting this error. not sure why. any help appreciated.
#ifndef Region_H
#define Region_H
#include "Stat.h"
#include "Day.h"
#include "Station.h"
#include "Analyzer.h"
#include "Region.h"
class Region {
private:
Station* _stations[MAX_STATION_COUNT];
int _stationCount=0;
int _currentStation;
public:
Region();
void load(std::ifstream &input);
void resetStationIteration();
Station* getNextStation();
Station* findStation(std::string& id);
private:
Station* addStation(std::string& id, std::string& name);
};
#endif
there is another class called station already so this should work, not sure why it wont. please tell if i need to add more code or detail im fairly new to c++ so need a lot of help.
here is the station class .h file
#ifndef Station_H
#define Station_H
#include "Stat.h"
#include "Day.h"
#include "Station.h"
#include "Analyzer.h"
#include "Region.h"
class Station {
private:
std::string _id;
std::string _name;
Day* _days[MAX_DAYS];
int _dayCount = 0;
int _currentDay = -1;
public:
Station(std::string& id, std::string& name);
void load(std::string& datetime, std::string& qgag, std::string& qpcp);
void resetDayIteration();
Day* getDayNext();
std::string getId();
std::string getName();
private:
Day* findDay(std::string& date);
Day* addDay(std::string& date);
};
#endif
ok thanks for all the answered questions so far i have used all your suggestions and fixed some of the errors, however, in trying to run my main function i get this error:
Running /home/ubuntu/workspace/cs1440-hw2/main.cpp
/tmp/ccxaejI8.o: In function `main':
main.cpp:(.text+0x1e0): undefined reference to `Region::Region()'
main.cpp:(.text+0x1f9): undefined reference to `Region::load(std::basic_ifstream<char, std::char_traits<char> >&)'
main.cpp:(.text+0x264): undefined reference to `Region::findStation(std::string&)'
main.cpp:(.text+0x28e): undefined reference to `Analyzer::analyze(Station*)'
main.cpp:(.text+0x2ae): undefined reference to `Region::resetStationIteration()'
main.cpp:(.text+0x2c9): undefined reference to `Analyzer::analyze(Station*)'
main.cpp:(.text+0x2d8): undefined reference to `Region::getNextStation()'
collect2: error: ld returned 1 exit status
Process exited with code: 1
and here is the main file so you guys can get a better perpective:
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include "Analyzer.h"
#include "Region.h"
#define MAX_DAYS 365
#define MAX_STATS 100
#define MAX_STATION_COUNT 20
bool split(const std::string& s, char delimiter, std::string elements[], int expectedNumberOfElements) {
std::stringstream ss;
ss.str(s);
std::string item;
int i=0;
while (std::getline(ss, item, delimiter) && i<expectedNumberOfElements) {
elements[i++] = item;
}
return (i==expectedNumberOfElements);
}
int main(int argc, char* argv[]) {
if (argc>1) {
std::ifstream inputStream(argv[1], std::ios_base::in);
Region region;
region.load(inputStream);
Analyzer analyzer;
if (argc>2) {
std::string stationId(argv[2]);
Station* station = region.findStation(stationId);
if (station!= nullptr)
analyzer.analyze(station);
}
else {
region.resetStationIteration();
Station *station;
while ((station = region.getNextStation()) != nullptr)
analyzer.analyze(station);
}
}
return 0;
}