I am writing a program that takes one file and compares its data to that of some bunch of other reference files. I created a class that takes a file path and uses it to open the file, then it parses the file and loads all of the data into memory. Everything works fine when I try to use a single instance of that class.
Next, I want to create a vector of such objects. Since my class uses an fstream object, I can't have a copy constructor and have to resort to passing by reference.
So my solution so far is something like this:
1 2 3 4 5 6 7 8 9 10 11
datafile mainfile;
vector<datafile*> otherfiles;
mainfile.openFile(filepath);
for(int i = 0; i < list_of_filepaths.size(); i++)
{
otherfiles.push_back(new datafile);
otherfiles.at(i)->openFile(list_of_filepaths.at(i));
}
The openFile() function has the function to parse the file already inside it. So when I open 'mainfile', I can access all the data inside and do whatever. However, this does NOT work for my vector of objects. I save the parsed data into another vector of 'int' type which is part of the 'datafile' class. When I check to see the size of the vector to see if there is any information there, it just gives me zero. So I know I am at least creating the objects, but not doing anything with them. I am now stuck. I don't know what I'm doing wrong, so I don't know how to fix it.