Alright so my problem is I am getting an error that says undefined reference to all of my functions related to DoubleLinked, DoubleLinked<string> dict, dict.add, etc. If anyone knows why that would be great. Thank you. Oh and if i add () to DoubleLinked<string> dict then i just have undefined reference errors to add and contains.
#include <iostream>
#include "DoubleLinked.h"
#include "Node.h"
#include <fstream>
#include <vector>
using namespace std;
int main()
{
cout << "Hello" << endl;
string st = "hello";
DoubleLinked<string> dict;
vector <string> phrase;
vector <string> Wrong;
dict.add(st);
ifstream fin;
fin.open("check.txt");
string word;
int c = 0;
while(fin >> word && c < phrase.size() )
{
phrase[c] == word;
c++;
}
fin.close();
int count = 0;
for(int i = 0; i < phrase.size(); i++)
{
string str = phrase[i];
if(!dict.contains(str))
{
Wrong[count] = phrase[i];
count++;
}
}
cout<<"The following words are spelled incorrectly: " <<endl;
for(int i = 0; i < Wrong.size(); i++)
cout << Wrong[i];
return 0;
}
#include "DoubleLinked.h"
#include "Node.h"
#include <cstddef>
template<class ItemType>
DoubleLinked<ItemType>::DoubleLinked() : headPtr(NULL), itemCount(0)
{
} // end default constructor
template<class ItemType>
DoubleLinked<ItemType>::DoubleLinked(const DoubleLinked<ItemType>& aBag)
{
itemCount = aBag->itemCount;
Node<ItemType>* origChainPtr = aBag->headPtr; // Points to nodes in original chain
if (origChainPtr == NULL)
headPtr = NULL; // Original bag is empty; so is copy
else
{
// Copy first node
headPtr = new Node<ItemType>();
headPtr->setItem(origChainPtr->getItem());
// Copy remaining nodes
Node<ItemType>* newChainPtr = headPtr; // Last-node pointer
while (origChainPtr != NULL)
{
origChainPtr = origChainPtr ->getNext(); // Advance pointer
// Get next item from original chain
ItemType nextItem = origChainPtr->getItem();
// Create a new node containing the next item
Node<ItemType>* newNodePtr = new Node<ItemType>(nextItem);
// Link new node to end of new chain
newChainPtr->setNext(newNodePtr);
//link to last node
newChainPtr->setPrev(origChainPtr);
// Advance pointer to new last node
newChainPtr = newChainPtr->getNext();
} // end while
newChainPtr->setNext(NULL); // Flag end of new chain
} // end if
} // end copy constructor
template<class ItemType>
DoubleLinked<ItemType>::~DoubleLinked()
{
clear();
} // end destructor
template<class ItemType>
bool DoubleLinked<ItemType>::isEmpty() const
{
return itemCount == 0;
} // end isEmpty
template<class ItemType>
int DoubleLinked<ItemType>::getCurrentSize() const
{
return itemCount;
} // end getCurrentSize
template<class ItemType>
bool DoubleLinked<ItemType>::add(const ItemType& newEntry)
{
Node<ItemType>* curr;
curr = headPtr;
// Add to beginning of chain: new node references rest of chain;
// (headPtr is null if chain is empty)
Node<ItemType>* nextNodePtr = new Node<ItemType>();
nextNodePtr->setItem(newEntry);
nextNodePtr->setNext(headPtr);// New node points to chain
headPtr-> prev = curr;
// Node<ItemType>* nextNodePtr = new Node<ItemType>(newEntry, headPtr); // alternate code
headPtr = nextNodePtr; // New node is now first node
itemCount++;
return true;
} // end add
template<class ItemType>
vector<ItemType> DoubleLinked<ItemType>::toVector() const
{
vector<ItemType> bagContents;
Node<ItemType>* curPtr = headPtr;
int counter = 0;
while ((curPtr != NULL) && (counter < itemCount))
{
bagContents.push_back(curPtr->getItem());
curPtr = curPtr->getNext();
counter++;
} // end while
return bagContents;
} // end toVector
template<class ItemType>
bool DoubleLinked<ItemType>::remove(const ItemType& anEntry)
{
Node<ItemType>* entryNodePtr = getPointerTo(anEntry);
bool canRemoveItem = !isEmpty() && (entryNodePtr != NULL);
if (canRemoveItem)
{
// Copy data from first node to located node
entryNodePtr->setItem(headPtr->getItem());
// Delete first node
Node<ItemType>* nodeToDeletePtr = headPtr;
headPtr = headPtr->getNext();
// Return node to the system
nodeToDeletePtr->setNext(NULL);
delete nodeToDeletePtr;
nodeToDeletePtr = NULL;
itemCount--;
} // end if
return canRemoveItem;
} // end remove
template<class ItemType>
void DoubleLinked<ItemType>::clear()
{
Node<ItemType>* nodeToDeletePtr = headPtr;
while (headPtr != NULL)
{
headPtr = headPtr->getNext();
// Return node to the system
nodeToDeletePtr->setNext(NULL);
delete nodeToDeletePtr;
nodeToDeletePtr = headPtr;
} // end while
// headPtr is NULL; nodeToDeletePtr is NULL
itemCount = 0;
} // end clear
template<class ItemType>
int DoubleLinked<ItemType>::getFrequencyOf(const ItemType& anEntry) const
{
int frequency = 0;
int counter = 0;
Node<ItemType>* curPtr = headPtr;
while ((curPtr != NULL) && (counter < itemCount))
{
if (anEntry == curPtr->getItem())
{
frequency++;
} // end if
counter++;
curPtr = curPtr->getNext();
} // end while
return frequency;
} // end getFrequencyOf
template<class ItemType>
bool DoubleLinked<ItemType>::contains(const ItemType& anEntry) const
{
return (getPointerTo(anEntry) != NULL);
} // end contains
template<class ItemType>
Node<ItemType>* DoubleLinked<ItemType>::getPointerTo(const ItemType& anEntry) const
{
bool found = false;
Node<ItemType>* curPtr = headPtr;
while (!found && (curPtr != NULL))
{
if (anEntry == curPtr->getItem())
found = true;
else
curPtr = curPtr->getNext();
} // end while
return curPtr;
} // end getPointerTo