试图通过生成二进制数来执行简单的入队/出队操作,但在line#18]中遇到错误Main:
,我将变量front的类型从private更改为public(在我将其设为public之前,它给出了error表示front is private)#include <iostream> #include "quetype.cpp" #include "quetype.h" #include <queue> using namespace std; int main() { QueType<string> q; int n = 10; q.Enqueue("1"); while (n--) { string s1 = q.front(); //expression cant be used as a function q.Dequeue(); cout << s1 << "\n"; string s2 = s1; q.Enqueue(s1.append("0")); q.Dequeue(s2.append("1")); } }
这发生了[[之后
。h文件:
#ifndef QUETYPE_H_INCLUDED
#define QUETYPE_H_INCLUDED
class FullQueue
{};
class EmptyQueue
{};
template<class ItemType>
class QueType
{
public:
QueType();
QueType(int max);
~QueType();
void MakeEmpty();
bool IsEmpty();
bool IsFull();
void Enqueue(ItemType);
void Dequeue(ItemType&);
int front;
//int rear;
//ItemType* items;
//int maxQueue;
private:
//int front;
int rear;
ItemType* items;
int maxQueue;
};
#endif // QUETYPE_H_INCLUDED
源cpp:
#include"quetype.h"
#include <queue>
template<class ItemType>
QueType<ItemType>::QueType(int max){
maxQueue=max+1;
rear=max;
front=max;
items= new ItemType[ maxQueue];
}
template<class ItemType>
QueType<ItemType>::QueType(){
maxQueue=501;
rear=maxQueue-1;
front=maxQueue-1;
items= new ItemType[ maxQueue];
}
template<class ItemType>
QueType<ItemType>::~QueType(){
delete[] items;
}
template<class ItemType>
void QueType<ItemType>::MakeEmpty(){
rear=maxQueue-1;
front=maxQueue-1;
}
template<class ItemType>
bool QueType<ItemType>::IsEmpty(){
return (rear==front);
}
template<class ItemType>
bool QueType<ItemType>::IsFull(){
return ((rear+1)%maxQueue==front);
}
template<class ItemType>
void QueType<ItemType>::Enqueue(ItemType newItem){
if(IsFull())
throw FullQueue();
else{
rear=(rear+1)%maxQueue;
items[rear]=newItem;
}
}
template<class ItemType>
void QueType<ItemType>::Dequeue(ItemType& Item){
if(IsEmpty())
throw EmptyQueue();
else{
front=(front+1)%maxQueue;
Item=items[front];
}
}
我做错了什么?
[试图通过生成二进制数来执行简单的入队/出队操作,但在第18行主程序中遇到错误:#include
#include“ quetype.cpp” #include“ quetype.h” #include&...
front