i hav write a coding regarding to lists topic. and i had found about 3 error which i cant solve. any1 here who can help me wif dis error? i m very appreciate 4 all of ur help..TQ..dis is my coding and the error..TQ
List.h
#ifndef LIST_H
#define LIST_H
template < class DataType>
class List
{
private:
class Node
{
public:
DataType data;
Node * link;
};
Node *pHead;
Node *pCurr;
int numItem;
public:
List();
~List();
void AddToFront();
void Traverse(DataType, int &);
void printData();
int NumberOfItem();
};
#endif
List.cpp
#include <iostream>
using namespace std;
#include "List.h"
template<class DataType>
List<DataType>::List()
{
numItem = 0;
pHead = 0;
}
template <class DataType>
List<DataType>::~List() {}
template <class DataType>
void List<DataType>::AddToFront()
{
DataType item;
Node *pNew = new Node;
cout << "Enter data : ";
cin >> item;
pNew->data = item;
pNew->link = pHead;
pHead = pNew;
numItem++;
}
template <class DataType>
void List <DataType>::printData()
{
pCurr = pHead;
while (pCurr != 0)
{
cout << pCurr->data << " ";
pCurr = pCurr->link;
}
cout << "\n";
}
template <class DataType>
int List<DataType>::NumberOfItem()
{
return numItem;
}
template <class DataType>
bool List<DataType>::Traverse (DataType target, int &loc)
{
if (numItem == 0)
cout <<"There is no item in the list" <<endl;
else
{
pCurr = pHead;
loc = 0;
while (pCurr -> data != target && pCurr -> link != 0)
{
pCurr = pCurr -> link;
loc++;
}
if (pCurr -> data == target)
return true;
else
return false;
}
}
ListMain.cpp
#include <iostream>
#include<string>
using namespace std;
#include "List.h"
void main()
{
int target;
int location;
List<int> list;
for (int i = 1; i <4; i++)
{
list.AddToFront();
}
cout << "\nNumber of Item Now: " <<list.NumberOfItem();
cout << "\nThe list are : " <<endl;
list.printData();
cout<<"\nEnter the search item : ";
cin>> target;
if (list.Traverse(target, location) == true)
{
cout<< "Item is found at location : "
<<location<<endl;
}
else
{
cout << "Item is not found \n";
}
}
ERROR:
c:\Documents and Settings\VeNTRiCaLiM\Desktop\assignment5\6example1\ListMain.cpp(24): warning C4805: '==' : unsafe mix of type 'void' and type 'bool' in operation
c:\Documents and Settings\VeNTRiCaLiM\Desktop\assignment5\6example1\ListMain.cpp(24): error C2120: 'void' illegal with all types
c:\Documents and Settings\VeNTRiCaLiM\Desktop\assignment5\6example1\List.cpp(66): error C2244: 'List<DataType>::Traverse' : unable to match function definition to an existing declaration
can tel me where should i change in order to solve the error?TQ