为什么会出现这个问题呀
error C2371: 'bool' : redefinition; different basic types头文件1.h
const int maxSize=50;
enum bool {false,true};
template<class T>
class Queue{
public:
Queue(){};
~Queue(){};
virtual void EnQueue(const T& x)=0;
virtual bool DeQueue(T& x)=0;
virtual bool getFront(T& x)=0;
virtual bool IsEmpty()const=0;
virtual bool IsFull()const=0;
virtual int getSize()const=0;
};
头文件sequeue.h
template<class T>
class SeQueue:public Queue<T>{
public:
SeQueue(int sz=10);
~SeQueue(){delete[] elements;}
bool int DeQueue(T& x);
bool getFront(T& x);
void makeEmpty(){front=rear=0;}
bool IsEmpty()const{return(front==rear)?true:false;}
bool IsFull()const{return((rear+1)%maxSize==front)?true:false;}
int getSize()const{return(rear-front+maxSize)%maxSize;}
friend ostream& operator <<(ostream& os,SeQueue<T>& Q)
{protected:
int rear,front;
T *elements;
int maxSize;
};
源文件
#include<assert.h>
#include<iostream.h>
#include"1.h"
#include"sequeue.h"
template<class T>
SeQueue<T>::SeQueue(int sz):front(0),rear(0),maxSize(0){
elements=new T[maxSize];
assert (elements!=NULL);
};//建立空队列
template<class T>
bool SeQueue<T>::EnQueue(const T& x){
if (IsFull()==true) return false;
elements[rear]=x;
rear=(rear+1)%maxSize;
return true;
};//入队
template<class T>
bool SeQueue<T>::DeQueue(const T& x){
if (IsEmpty()==true) return false;
x=elements[front];
front=(front+1)%maxSize;
return true;
};//出队
template<class T>
bool SeQueue<T>::DeQueue(const T& x){
if (IsEmpty()==true) return false;
x=elements[front];
return true;
};//取对头
template<class T>
ostream& operator <<(ostream& os,SeQueue<T>& Q){
os<<"front="<<Q.front<<",rear="<<Q.rear<<endl;
for(int i=front;i!=rear;i=(i+1)%maxSize;)
os<<i<<":"<<Q.elements[i]<<endl;
return os;
};//元素的重载
void main()
{
int maxSize,number,select=5;
char s;
cout<<"\n请输入对的大小:"<<endl;
cin>>maxSize;
Queue<char> Queue(maxSize);
while(select!=4)
{
cout<<"\n\t\t\t************操作菜单*****************\n";
cout<<"\t\t\t\t 1 入队"<<endl;
cout<<"\t\t\t\t 2 出队"<<endl;
cout<<"\t\t\t\t 3 取队头元素"<<endl;
cout<<"\t\t\t\t 4 退出"<<endl;
cout<<"\t\t\t************请选择序号*****************\n";
cin>>select;
switch(select)
{
case 1:
cout<<"请输入一个队列并以.结束"<<endl;
cin>>s;
while(s!='.')
{
SeQueue.EnQueue(s);
cin>>s
}
break;
case 2:
cout<<"请输入出队字符数:";
cin>>number;
cout<<"\n出队元素依次为:";
for(int i=0;i<number;i++)
if (Se!Queue.IsEmpty()) cout<<SeQueue.DeQueue()<<" ";
break;
case 3:
if (SeQueue.IsEmpty()){cout<<"队空"<<endl;break;}
cout<<"队头元素为:"<<SeQueue.getFront();
break;
case 4:
break;
}
}
cout<<"谢谢使用"<<endl;
}