Hi,
what is wrong in this code ?
It is giving the error as below,
Functions containing while are not expanded inline. This while is in ~JList().
Functions containing for are not expanded inline. This is in T* Item(int Index)
The code is,
#ifndef JLIST_HPP
#define JLIST_HPP
template <class T> class JList
{
struct Cell
{
T * Data;
Cell *Next;
};
struct Cell *Head;
public:
JList()
{
Head = NULL;
}
~JList()
{
Cell * Current = Head;
Cell * Next = NULL;
while(Current)
{
Next = Current->Next;
delete Current->Data;
delete Current;
Current = Next;
}
}
T * Item(int Index)
{
Cell *Next, *Current = Head;
for(int i=0; ((i<Index) && (Current != 0)); i++)
{
Next = Current->Next;
Current = Next;
}
return Current->Data;
}
int Add(T * NewData)
{
int i=0;
Cell * Current = Head;
Cell * Previous = NULL;
while(Current)
{
Previous = Current;
Current = Current->Next;
i++;
}
if (Previous)
{
Previous->Next = new Cell;
Current = Previous->Next;
Current->Data = NewData;
Current->Next = NULL;
}
else
{
Head = new Cell;
Head->Data = NewData;
Head->Next = NULL;
}
return i;
}
int Delete(int Index)
{
Cell * Current = Head;
Cell * Previous=NULL, *Next=NULL;
for(int i=0; ((i<Index) && (Current != NULL)); i++)
{
Previous = Current;
Current = Current->Next;
if (Current) Next = Current->Next;
else Next = NULL;
}
if (Previous)
{
Previous->Next = Next;
delete Current->Data;
delete Current;
return 1;
}
else
{
//This is the case when you delete the first element.
//Or you delete an item from an empty list
if (Current)
{
Head = Current->Next;
delete Current->Data;
delete Current;
return 1;
}
}
return 0;
}
int Count()
{
Cell * Current = Head;
int i=0;
while(Current)
{
Current = Current->Next;
i++;
}
return i;
}
};
#endif
Please give me the solution.