这代码能编译通过,但是连接时有错误,请大虾帮我看一下!谢谢了!
#ifndef NODE_CLASS
#define NODE_CLASS
template <class T>
class Node
{
private :
Node <T> *next;
public:
T DaTA;
Node (const T &item,Node <T> *ptrnext=NULL);
void InsertAfter(Node <T> *p);
Node <T> *DeleteAfter (void );
Node <T> *NextNode (void )const;
};
template <class T>
Node <T> ::Node (const T &item,Node <T> *ptrnext):data(item),next(ptrnext){}
template <class T>
Node <T> *Node <T>::NextNode (void) const
{return next;}
template <class T>
void Node <T>::InsertAfter(Node <T> *p)
{p->next=next;
next=p;
}
template <class T>
Node<T> *Node <T>::DeleteAfter(void)
{Node<T> *tempPtr=next;
if(next==NULL)
return NULL;
next=tempPtr->next;
return tempPtr;
}
#endif
#ifndef LINKEDLIST_CLASS
#define LINKEDLIST_CLASS
#include <iostream>
#include <cstdlib>
using namespace std;
#ifndef NULL
const int NULL=0;
#endif
template <class T>
class LinkedList
{private :
Node <T> *front,*rear;
Node <T> *prevPtr,*currPtr;
int size ;
int position;
Node<T> *GetNode (const T &item,Node<T> *ptrNext=NULL);
void FreeNode (Node <T> *p);
void CopyList(const LinkedList<T> &L);
public:
LinkedList( void );
LinkedList(const LinkedList<T> &L);
~LinkedList(void );
LinkedList<T> &operator =(const LinkedList <T> &L);
int ListSize(void )const;
int ListEmpty(void) const;
void Reset (int pos=0);
void Next(void );
int EndOfList(void) const;
int CurrentPosition(void) const;
void InsertFront(const T& item);
void InsertRear(const T &item);
void InsertAt(const T &item);
void InsertAfter(const T &item);
T DeleteFront(void );
void DeleteAt(void );
T &Data(void);
void ClearList(void);
};
#endif
#include<iostream>
using namespace std;
void main()
{LinkedList <int > Link;
int i,key,item;
for(i=0;i<10;i++)
{cin>>item;
Link.InsertFront(item);
}
cout<<"List:"<<endl;
Link.Reset();
while(!Link.EndOfList())
{ cout<<Link.Data()<<" ";
Link.Next();
}
cout<<endl;
cout<<" Enter the number you want to delete :"<<endl;
cin>>key;
Link.Reset();
while(!Link.EndOfList())
{if(Link.Data()==key)
Link.DeleteAt();
Link.Next();
}
cout<<"List:"<<endl;
Link.Reset();
while(!Link.EndOfList())
{cout<<Link.Data()<<" ";
Link.Next();
}
cout<<endl;
}
连接时的错误:
-----------------Configuration: 3333 - Win32 Debug--------------------
Linking...
3333.obj : error LNK2001: unresolved external symbol "public: __thiscall LinkedList<int>::~LinkedList<int>(void)" (??1?$LinkedList@H@@QAE@XZ)
3333.obj : error LNK2001: unresolved external symbol "public: void __thiscall LinkedList<int>::DeleteAt(void)" (?DeleteAt@?$LinkedList@H@@QAEXXZ)
3333.obj : error LNK2001: unresolved external symbol "public: void __thiscall LinkedList<int>::Next(void)" (?Next@?$LinkedList@H@@QAEXXZ)
3333.obj : error LNK2001: unresolved external symbol "public: int & __thiscall LinkedList<int>::Data(void)" (?Data@?$LinkedList@H@@QAEAAHXZ)
3333.obj : error LNK2001: unresolved external symbol "public: int __thiscall LinkedList<int>::EndOfList(void)const " (?EndOfList@?$LinkedList@H@@QBEHXZ)
3333.obj : error LNK2001: unresolved external symbol "public: void __thiscall LinkedList<int>::Reset(int)" (?Reset@?$LinkedList@H@@QAEXH@Z)
3333.obj : error LNK2001: unresolved external symbol "public: void __thiscall LinkedList<int>::InsertFront(int const &)" (?InsertFront@?$LinkedList@H@@QAEXABH@Z)
3333.obj : error LNK2001: unresolved external symbol "public: __thiscall LinkedList<int>::LinkedList<int>(void)" (??0?$LinkedList@H@@QAE@XZ)
Debug/3333.exe : fatal error LNK1120: 8 unresolved externals
Ö´ÐÐ link.exe ʱ³ö´í.
3333.exe - 1 error(s), 0 warning(s)