Hello everyone, I am doing an assignment where I need to implement queues as linked lists. So far the linked lists part is going well but the next part is to add persistence. I was given this function to read the structs into a list from a binary file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
void restoreList(course*& a)
{
fstream fin;
fin.open("courses.dat", ios::binary|ios::in);
if (!fin)
return;
// read the number of objects from the disk file
int nRecs;
fin.read((char*)&nRecs, sizeof(int));
// read the objects from the disk file
for (int i = 0; i < nRecs; i++)
{
course* t = new course;
fin.read((char*)t, sizeof(course));
if (a == nullptr) //I wrote this part of the program to build a linked list
{
a = t;
a->next = nullptr;
}
else
{
course *p = a;
course *prev = 0;
for (p, prev; p; prev = p, p = p->next);
prev = t;
prev->next = 0;
}
}
fin.close();
}
|
I added a prototype and called the function in this way. And yes I included fstream.
1 2
|
void restorelist(course *&); //function prototype
restorelist(start); // is how I called the function in the main
|
This is the struct I am attempting to read
1 2 3 4 5 6 7 8
|
struct course
{
string course_Name;
string term;
int units;
char grade;
course *next; //link
};
|
When I added this part in I get an error when building.
Severity Code Description
Error LNK1120 1 unresolved externals
Severity Code Description Project File Line
Error LNK2019 unresolved external symbol "void __cdecl restorelist(struct course * &)" (?restorelist@@YAXAAPAUcourse@@@Z) referenced in function _main
I've attempted to read on these errors but I am afraid I still have not much of a clue as to why this has happened. Likewise I did some reading on binary file I/O and it seems to me that the function I was provided should work but I know very little about reading and writing to binary at this point so I can't say for certain.
Much thanks for the assistance.