I cannot solve this, I’m almost accepting the fact that it might be a memory issue with my machine at this point.
I have this initializer:
Search::Search(ifstream& inFile)
{
int id = 0;
int i = 0;
inFile >> id;
while (inFile) {
if(i < SEARCH_DATA_SIZE) {
SearchDataFirst[i] = id;
SearchDataFirstSorted[i] = id;
} else if(i >= SEARCH_DATA_SIZE) {
SearchDataLast[i] = id;
SearchDataLastSorted[i] = id;
}
i++;
inFile >> id;
}
}
And in my header i have private data like so:
const int SEARCH_DATA_SIZE = 20;
int SearchDataFirst[SEARCH_DATA_SIZE]; int SearchDataLast[SEARCH_DATA_SIZE]; int SearchDataFirstSorted[SEARCH_DATA_SIZE]; int SearchDataLastSorted[SEARCH_DATA_SIZE];
The initializer is getting the first 20 ints from inFile, storing them, and then going to the next records and storing those in separate arrays,
When I do a print of the arrays, SearchDataFirstSorted has the values of SearchDataLast, even though there is no possible way ever that this could happen. SearchDataLastSorted has weird funky numbers.
SearchedDataFirst is fine.
I have never been this frustrated with a programming language.
Hopefully you can help.
There is nothing else going on, only the initializer is being called at this point.
The problem is that if
i >= SEARCH_DATA_SIZE, thenSearchDataLast[i]is pointing outsideSearchDataLast! What you really need is something like this:That is, you need to reset
iback to zero after you’re done populatingSearchDataFirstand before you start populatingSearchDataLast.