"1>List.obj : error LNK2019: unresolved external symbol "public: void __thiscall list::resetlist(void)" (?resetlist@list@@QAEXXZ) referenced in function _main"
for every single function contained in my class named "list" in my .h file when I tried to build the solution. It says "LNK", which I assume means a link error.
I don't know why, it seems like I did everything alright.
/*
SPEC file. This file gives the specifications of a list data type.
*/
#include <string>
constint maxsize = 100; // maximum number of components.
typedefint itemtype;
// type of each component... an int every time? how?
//Because the functions who actually need the type of data all accept the data in the database; ints.
class list
{
public:
list();
// constructor, defined in the .cpp file, it makes an empty list.
void insert(itemtype item);
// if list is not full (that item doesn't take up the 100th space), item is in the list and LENGTH of list increases
// where length is the number of spaces used
void deleteitem(itemtype item); // "delete" is a reserved word
// a given item is removed from the list, is the length subtracted by one? I'm not sure.... I think that's assumed.
void resetlist();
// the current position is reset to the first position.
itemtype getnextitem();
// resetlist() is called if an insert or delete has happened
// hasnext() needs to run to tell it if there is something coming after the current value.
bool hasnext() const;
// tells if there is an entry after the current one in the list.
bool isempty() const;
// returns true if the list is empty
bool isfull() const;
// returns true if the list is full
bool isthere (itemtype itemname) const;
// returns true if an item of type _itemtype_ of value _itemname_ is in the list.
int getlength() const;
// returns length of list.
private: // why does this need to be private?
int length;
int currentpos;
itemtype data[maxsize]; // the array of length maxsize = 100
};
// it reads the temperatures from a file and ignores duplicates. It ignores high temperatures and deletes only 1337.
#include <string>
#include <fstream>
#include "list.h"
#include <iostream>
usingnamespace std;
int main()
{
ifstream sourcefile;
ofstream output;
string filename;
cout << "imput the name of the file where the temperature data is" << endl << '(';
cin >> filename;
sourcefile.open(filename.c_str());
output.open("output.txt");
if (!sourcefile)
{
cout << "imput failed" << endl;
return 1;
}
// TEST CHECKPOINT --- OK
list names;
itemtype reader;
sourcefile >> reader; //primes while loop.
while(sourcefile && !names.isfull()) // if there is more data and the array is not full....
{
if(!names.isthere(reader) && reader < 200) // sends <reader> to the function isthere() which checks if the data is already there.
// if it is, it will return the bool value true, and make the if statement false.
names.insert(reader);
// if the data represented by reader does not already exist, it will add it to the database.
sourcefile >> reader;
}
cout << "Number of unique readings: " << names.getlength() << endl;
cout << "here is the list of data" << endl << endl;
while(names.hasnext())
{
reader = names.getnextitem();
cout << reader << endl;
}
names.deleteitem(1337);
names.resetlist();// deletes 1337 automatically
return 0;
}
Also, is there any way to use this program on a grouping of strings rather than integers? I tried to switch the typedef statement to
"typedef string itemtype" but it didn't seem to want to do that.