I'm using MVS C++ 6.0 Compiler,I can't type ".h" files and ".cpp" files into the different files.Compiler informed errors that:
"error LNK2001: unresolved external symbol "public: __thiscall Queue<int>::~Queue<int>(void)" (??1?$Queue@H@@QAE@XZ)
error LNK2001: unresolved external symbol "public: enum ErrorCode __thiscall Queue<int>::Serve(void)" (?Serve@?$Queue@H@@QAE?AW4ErrorCode@@XZ)
error LNK2001: unresolved external symbol "public: enum ErrorCode __thiscall Queue<int>::Append(int const &)" (?Append@?$Queue@H@@QAE?AW4ErrorCode@@ABH@Z)
error LNK2001: unresolved external symbol "public: __thiscall Queue<int>::Queue<int>(void)" (??0?$Queue@H@@QAE@XZ)
Debug/Queue.exe : fatal error LNK1120: 4 unresolved externals
"
So I have to type contents of ".h" files and ".cpp" files into a file and Compiler doesn't catch errors,but it's very long .I don't understand what these errors is......Everybody can help me...Thanks very much
This my code:
"Queue.h"
Code:
#ifndef QUEUE_H
#define QUEUE_H
#include "NodeQueue.h"
enum ErrorCode{sucess, overflow,underflow};
template <class Entry>
class Queue{
public:
Queue();
~Queue();
Queue(const Queue<Entry> &Qqueue);
void operator=(const Queue<Entry> &Qqueue);
bool Empty() const;
ErrorCode Append(const Entry &item);
ErrorCode Serve();
ErrorCode Retrieve(Entry &item) const;
bool Full() const;
int Size() const;
void Clear();
private:
int count;
Node<Entry> *pfront,*ptail;
};
#endif
"NodeQueue.h"
Code:
#ifndef NODEQUEUE_H
#define NODEQUEUE_H
template <class Entry>
struct Node{
Entry entry;
Node<Entry> * next;
Node();
Node(Entry item,Node<Entry> *p=NULL);
};
#endif
"NodeQueue.cpp"
Code:
#include "NodeQueue.h"
template <class Entry>
Node<Entry>::Node(){
next = NULL;
}
template <class Entry>
Node<Entry>::Node (Entry item,Node<Entry> * p){
entry = item;
next = p;
}
"Queue.cpp"
Code:
include <iostream>
#include "NodeQueue.h"
#include "Hangdoi.h"
using namespace std;
template <class Entry>
Queue<Entry>::Queue(){
pfront = ptail = NULL;
count = 0;
}
template <class Entry>
Queue<Entry>::~Queue(){
while(!Empty()){
Serve();
delete pfront;
delete ptail;
}
template <class Entry>
ErrorCode Queue<Entry>:: Append(const Entry &item){
Node<Entry> * ptam = new Node<Entry>(item);
if (ptam==NULL)
{
cout<<"Hang doi da day!";
return overflow;
}
if (ptail==NULL)
pfront = ptail = ptam;
else
{
ptail->next = ptam;
ptail = ptail->next;
count++;
}
return sucess;
}
template <class Entry>
ErrorCode Queue<Entry>::Serve(){
if (pfront==NULL)
{
cout<<"Hang doi da rong!";
return underflow;
}
else
{
Node<Entry> * pgiu = pfront;
pfront = pfront -> next;
if (pfront==NULL)
ptail = pfront;
delete pgiu;
count--;
}
return sucess;
}
template <class Entry>
bool Queue<Entry>::Empty() const {
if (pfront== NULL)
return true;
else
return false;
}
template <class Entry>
ErrorCode Queue<Entry>::Retrieve(Entry &item) const{
Node<Entry> * ptam = Node<Entry>(pfront->entry,pfront->next);
if (pfront==NULL)
{
cout<<"Hang doi da rong!";
return underflow;
}
else
cout<<ptam->entry;
return sucess
}
template <class Entry>
void Queue<Entry>::Clear(){
while (pfront!= NULL)
Serve();
return sucess;
}
template <class Entry>
bool Queue<Entry>::Full() const{
Entry thu;
Node <Entry> * pthu;
try
{
pthu = new Node<Entry>;
delete pthu;
return false;
}
catch(std::bad_alloc exception)
{
return true;
}
}
template <class Entry>
int Queue<Entry>::Size() const{
return count;
}
template <class Entry>
void Queue<Entry>::operator =(const Queue<Entry> &Qqueue){
Node<Entry> * pfrontsao,*ptailsao,*pduyet,*pfronttam = Qqueue.pfront, *ptailtam = Qqueue.ptail;
if (pfronttam==NULL) pfrontsao=NULL;
else{
pfrontsao = pduyet = new Node<Entry>(pfronttam->entry);
ptailsao = new Node<Entry>(ptailtam->entry);
while(pfronttam->next != NULL)
{
pfronttam = pfronttam->next;
pduyet->next = new Node<Entry>(pfronttam->entry);
pduyet = pduyet->next;
}
while (!Empty())
Serve();
pfront = pfrontsao;
ptail = ptailsao;
}
}
template <class Entry>
Queue<Entry>::Queue(const Queue<Entry> &Qqueue){
Node<Entry> * pduyet,*pfronttam = Qqueue.pfront,*ptailtam = Qqueue.ptail;
if (pfronttam==NULL) pfront = NULL;
else
{
pfront = pduyet = new Node<Entry>(pfronttam->entry);
ptail = new Node<Entry>(ptailtam->entry);
while (pfronttam->next != NULL){
pfronttam = pfronttam->next;
pduyet->next = new Node<Entry>(pfronttam->entry);
pduyet = pduyet->next;
}
}
}
}
"UseQueue.cpp"
Code:
#include <iostream>
#include <conio.h>
#include "Queue.h"
#include "NodeQueue.h"
using namespace std;
void main(){
Queue<int> Queue1;
Queue1.Append(5);
Queue1.Append(6);
Queue1.Append(1);
Queue1.Append(8);
Queue1.Serve();
Queue1.Serve();
getch();
}
Program couldn't run.It informed these above errors.But when I typed them(files) into a same file,it run...