Okay, I know what's wrong with my program but I don't know what to do to fix it.
I have to take a program we previous made and make it a template class. Okay, sounds easy enough. I know all the writing it right cause it ran fine before, now the problem is the stupid ItemType in my struct and (possibly) one later in my main.
Excluding all the code in between which can be corrected once I know the answer, this is the section code I'm focusing on.
typedef NodeType* NodePtr;
struct NodeType
{
ItemType item;
NodePtr next;
};
template<class ItemType>
List<ItemType>::~List()
// Post: All the components are deleted.
{
NodeType* tempPtr;
while (listPtr != NULL)
{
tempPtr = listPtr;
listPtr = listPtr->next;
delete tempPtr;
}
}
int main ()
{ List<int> a;
ItemType element;
ifstream InData;
InData.open ("int.dat");
if (InData.is_open())
{ while (InData >> element)
{ a.Insert(element); }
}
...
return 0;
}
I need struct "ItemType item" to be affected by my template <class ItemType> so that it changes to whatever value is needed and for the main "ItemType element" to be affected by it as well (not sure if this is possible, but I'm asking anyway).
So, how do I do that and how does it affect the other pieces of code that use my struct NodeType?
I know I need to put the <class ItemType> in front of the struct like I did later in the destructor, but what else is needed besides that piece. That's really what has me puzzled.