UITLITY.H的源文件如下:
#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
enum Error_code { success, fail, range_error, underflow, overflow, fatal,
not_present, duplicate_error, entry_inserted, entry_found,
internal_error };
bool user_says_yes();
====================
UTILITY.CPP 的源文件
#include "UTILITY.H" //与头文件相连
bool user_says_yes()
{
int c;
bool initial_response = true;
do { // Loop until an appropriate input is received.
if (initial_response)
cout << " (y,n)? " << flush;
else
cout << "Respond with either y or n: " << flush;
do { // Ignore white space.
c = cin.get();
} while (c == '\n' || c ==' ' || c == '\t');
initial_response = false;
} while (c != 'y' && c != 'Y' && c != 'n' && c != 'N');
return (c == 'y' || c == 'Y');
}
===============================================
queue.h的源文件
const int maxqueue=20;
class Queue {
public:
Queue();
bool empty() const;
Error_code append(const Queue_entry &item);
Error_code retrieve(Queue_entry &item) const;
protected:
int count;
int front,rear;
Queue_entry entry[maxqueue];
};
==========================================
queue.cpp 的源文件
#include "queue.h" //与头文件相连
Queue::Queue()
/*Post:The Queue is initialized to be empty.*/
{
count=0;
rear=maxqueue-1;
front=0;
}
bool Queue::empty() const
/*Post:Return true if the Queue is empty,otherwise return false.*/
{
return count==0;
}
Error_code Queue::append(const Queue_entry &item)
/*Post: item is added to the rear if the Queue.if the Queue is full return an
Error_code of overflow and leave the Queue unchanged.*/
{
if(count>=maxqueue) return overflow;
count++;
rear=((rear+1)==maxqueue) ? 0:(rear+1);
entry[rear]=item;
return success;
}
Error_code Queue::retrieve(Queue_entry &item) const
/*Post:The front of the Queue retrieved to the output parameter item. if the
Queue is empty return an Error_code of underflow.*/
{
if(count<=0) return underflow;
item=entry[front];
return success;
}
======================
如果将主函数设置如下时,出现错误链接的信息,头文件
"UITLITY.H"总是链接不上。请帮我找找原因!!
#include "UITLITY.H" //链接UITLITY.H
typedef double Queue_entry;
#include "queue.h"
void main()
{
...........
}