Hello, this is sort of a follow up to my last question. I figured out my problem there, and it was I had to use templates. My problem now is this is my first time using templates, and here are my errors:
runSortedLinkedList.cxx: In function `int main()':
runSortedLinkedList.cxx:49: error: no matching function for call to `FileToList
(SortedType<ItemType>&, std::ifstream&, std::ofstream&)'
runSortedLinkedList.cxx:50: error: no matching function for call to `ListToFile
(SortedType<ItemType>&, std::ofstream&)'
runSortedLinkedList.cxx: In function `void FileToList(SortedType<int>&,
std::ifstream&, std::ofstream&)':
runSortedLinkedList.cxx:69: error: no matching function for call to `
SortedType<int>::InsertItem(ItemType&)'
SortedLinkedList.h:49: error: candidates are: void
SortedType<ItemType>::InsertItem(ItemType) [with ItemType = int]
runSortedLinkedList.cxx:71: error: no matching function for call to `ListToFile
(SortedType<int>&, std::basic_ofstream<char, std::char_traits<char> >&)'
runSortedLinkedList.cxx:79: error: no matching function for call to `ListToFile
(SortedType<int>&, std::basic_ofstream<char, std::char_traits<char> >&)'
runSortedLinkedList.cxx:84: error: no matching function for call to `
SortedType<int>::DeleteItem(ItemType&)'
SortedLinkedList.h:56: error: candidates are: void
SortedType<ItemType>::DeleteItem(ItemType) [with ItemType = int]
runSortedLinkedList.cxx:86: error: no matching function for call to `ItemType::
GetItemFromFile(ItemType&)'
ItemType.h:39: error: candidates are: char
ItemType::GetItemFromFile(std::ifstream&)
runSortedLinkedList.cxx: In function `void ListToFile(SortedType<int>&,
std::ofstream&)':
runSortedLinkedList.cxx:105: error: no matching function for call to `
SortedType<int>::GetNextItem(ItemType&)'
SortedLinkedList.h:69: error: candidates are: void
SortedType<ItemType>::GetNextItem(ItemType&) [with ItemType = int]
I know I should have most of my code correct, it's just in my runSortedLinkedList file that I am having problems declaring it. Thank you for your help. Here is my code:
I have not included my ItemType files (which you shouldn't really need) or my SortedLinkedList.cxx (which you may need). Thanks again!!Code:SortedType.h #include "ItemType.h" template<class ItemType> struct NodeType { ItemType info; NodeType* next; }; template<class ItemType> class SortedType { public: SortedType(); // Constructor // Postcondition: Empty list is created ~SortedType(); // Destructor // Postcondition: List is destroyed SortedType(const SortedType& otherList); // Copy-constructor // Postcondition: List is created as a duplicate of otherList bool IsFull() const; // Determines whether list is full. // Post: Function value = (list is full) int LengthIs() const; // Determines the number of elements in list. // Post: Function value = number of elements in list. void MakeEmpty(); // Initializes list to empty state. // Post: List is empty. void RetrieveItem(ItemType& item, bool& found); // Retrieves list element whose key matches item's key // (if present). // Pre: Key member of item is initialized. // Post: If there is an element someItem whose key matches // item's key, then found = true and item is a copy // of someItem; otherwise found = false and item is // unchanged. // List is unchanged. void InsertItem(ItemType item); // Adds item to list. // Pre: List is not full. // item is not in list. // Post: item is in list // (added) // list order is preserved void DeleteItem(ItemType item); // Deletes the element whose key matches item's key. // Pre: Key member of item is initialized. // One and only one element in list has a key matching // item's key. // Post: No element in list has a key matching item's key. void ResetList(); // Initializes current position to end of list for iteration // through list. // Post: Current position is at end of list. void GetNextItem(ItemType& item); // Gets the next element in list. // Pre: // Post: If Current position is at end, currentPos points to head of list, // else item is copy of element at current position. // Advance current position. void Print(); private: NodeType<ItemType>* listData; int length; NodeType<ItemType>* currentPos; }; runSortedType.cxx #include "SortedLinkedList.h" #include <fstream> using namespace std; template<class ItemType> void FileToList(SortedType<int>& intList, ifstream& inFile, ofstream& outFile); // PURPOSE: To take an item from the GetItemFromFile function, and to add // it if addOrDelete was 'A' or delete it if addOrDelete was 'D'. Also to // print error messages accordingly. // INPUT: intList, inFile // PRE: intList is declared, inFile is OK, outFile is OK // OUTPUT: outFile // POST: An item(s) were written to intList with an error message if // according // NOTE: none template <class ItemType> void ListToFile(SortedType<int>& intList, ofstream& outFile); // PURPOSE: To print the list to a file as long as data exists in the list // INPUT: intList // PRE: intList is declared and OK, outFile is OK // OUTPUT: outFile // POST: All items are written to the outFile // NOTE: none int main() { ifstream inFile; ofstream outFile; SortedType<int> intList; FileToList(intList, inFile, outFile); ListToFile(intList, outFile); return 0; } void FileToList(SortedType<int>& intList, ifstream& inFile, ofstream& outFile) { ItemType item; char addOrDelete; inFile.open("in.data"); intList.MakeEmpty(); addOrDelete = item.GetItemFromFile(inFile); while (inFile) { if (addOrDelete == 'A') { if (!intList.IsFull()) intList.InsertItem(item); else{ ListToFile(intList, outFile); item.PrintLstFullErr(outFile); } addOrDelete = item.GetItemFromFile(inFile); } else if (addOrDelete == 'D') { if(intList.LengthIs() == 0){ ListToFile(intList, outFile); item.PrintEmptyLstErr(outFile); } else { intList.DeleteItem(item); } addOrDelete = item.GetItemFromFile(item); } } } void ListToFile(SortedType<int>& intList, ofstream& outFile) { ItemType item; int length; outFile.open("out.data"); intList.ResetList(); length = intList.LengthIs(); outFile << "STUDENT ID" << setw(6) << "EXAM1" << setw(10) << "EXAM2" << setw(9) << "FINAL" << setw(9) << "PROG" << setw(14) << "QUIZZES" << endl; for (int count = 1; count <= length; count++) { intList.GetNextItem(item); item.WriteItemToFile(outFile); } }



LinkBack URL
About LinkBacks



fstream&)':
:
eleteItem(ItemType)'