To make it easier to read, only the relevant code is below, and due to circumstances beyond my control im stuck using Xcode for the next week or so (hate this debugger).
I need help fixing a seg_fault in my current program. It occurs the last time "buildPaths" is called. I feel like im going outside of the "thePaths" vector, but the fixes I've tried did nothing.
Please tell me either
A) A solution, where the problem was, how to avoid it, how to go about fixing it
B) Where the problem is, how to go about fixing it, how to avoid it
Remember i basically have no debugger for a while
Sample input
1
3 2
1 2
2 3
Output:
2
1 3
EDIT: If you know of something better than Xcode for a mac please share
struct path {
int from;
int to;
bool good;
};
struct store {
int numBadPaths;
bool open;
};
class aMap {
private:
int next;
int numberCities;
vector <path>thePaths;
vector <store>theStores;
bool testMap();
void tallyBadPaths ();
public:
void initialize (int numCities, int numPaths);
void buildPaths (int form , int to);
void removeStores();
void print();
};
void aMap::buildPaths(int from, int to){
thePaths[next].from = from;
thePaths[next].to = to;
thePaths[next].good = false;
next++;
}
void aMap::initialize(int numCities, int numPaths) {
theStores.resize(numCities);
thePaths.resize(numPaths);
numberCities = numCities;
next = 0;
for (int i = 0; i < theStores.size(); i++) {
theStores[i].open = true;
}
}
int main () {
int numCases, numCities, numPaths, from, to;
aMap Boston;
cin >> numCases;
for (int i = 0; i<numCases; i++) {
cin >> numCities >> numPaths;
Boston.initialize(numCities, numPaths);
for (int j = 0; j<numPaths; j++) {
cin >> from >> to;
cout << "Build Paths" << endl;
Boston.buildPaths(from, to);
}
cout << "Remove Stores";
Boston.removeStores();
Boston.print();
}
return 0;
}