CountedQueTypeがうまく継承できないせいでエラーがでています。
継承するクラスに含まれているヘッダーファイルは、もう一度includeしないといけないのでしょうか?
ご指摘ください、よろしくお願いします。
コード /* * CountedQueType.cpp * * Created on: 2015/12/02 * Author: 礼央 */ #include"CountedQueType.h" using namespace std; void CountedQueType::Enqueue(ItemType newItem) { try { QueType::Enqueue(newItem); length++; } catch(FullQueue) { throw FullQueue(); } } void CountedQueType::Dequeue(ItemType& item){ try{ QueType::Dequeue(item); length--; }catch(EmptyQueue){ throw EmptyQueue(); } } int CountedQueType::LengthIs() const{ return length; } CountedQueType::CountedQueType(int max) :QueType(max){ length=0; }
コード /* * CountedQueType.h * * Created on: 2015/12/02 * Author: 礼央 */ typedef char ItemType; class CountedQueType:public QueType{ public: CountedQueType(int max); void Enqueue(ItemType newItem); void Dequeue(ItemType& item); int LengthIs() const; private: int length; }; #endif /* COUNTEDQUETYPE_H_ */
コード /* * ItemType.cpp * * Created on: 2015/11/18 * Author: 礼央 */ #include<iostream> #include"ItemType.h" #include"QueType.h" using namespace std; ItemType::ItemType(){ this->value=0; } RelationType ItemType::ComparedTo(ItemType otheritem){ if(value<otheritem.value) return LESS; else if(value>otheritem.value) return GREATER; else return EQUAL; } void ItemType::Initialize(int value){ this->value=value; } void ItemType::print() const{ cout<<this->value<<endl; } ItemType::~ItemType(){ this->value=0; }
コード /* * ItemType.h * * Created on: 2015/11/18 * Author: 礼央 */ #ifndef ITEMTYPE_H_ #define ITEMTYPE_H_ const int MAX_ITEMS=5; enum RelationType{LESS,GREATER,EQUAL}; class ItemType{ private: int value; public: ItemType(); RelationType ComparedTo(ItemType); void Initialize(int); void print() const; ~ItemType(); }; #endif /* ITEMTYPE_H_ */
コード /* * QueType.cpp * * Created on: 2015/12/01 * Author: 礼央 */ #include<iostream> #include"ItemType.h" #include"QueType.h" using namespace std; QueType::QueType(int max) { maxQue = max + 1; front = maxQue - 1; rear = maxQue - 1; items = new ItemType[maxQue]; } QueType::QueType() { maxQue = 501; front = maxQue - 1; rear = maxQue - 1; items = new ItemType[maxQue]; } QueType::~QueType() { delete[] items; } void QueType::MakeEmpty() { front = maxQue - 1; rear = maxQue - 1; } bool QueType::IsEmpty() const { return (rear == front); } bool QueType::IsFull() const { return ((rear + 1) % maxQue == front); } void QueType::Enqueue(ItemType newItem) { if (IsFull()) throw FullQueue(); else { rear = (rear + 1) % maxQue; items[rear] = newItem; } } void QueType::Dequeue(ItemType &item) { if (IsEmpty()) throw EmptyQueue(); else { front = (front + 1) % maxQue; item = items[front]; } }
コード/* * QueType.h * * Created on: 2015/12/01 * Author: 礼央 */ #ifndef QUETYPE_H_ #define QUETYPE_H_ #include"ItemType.h" class FullQueue{}; class EmptyQueue{}; class QueType { public: QueType(int max); QueType(); ~QueType(); void MakeEmpty(); bool IsEmpty() const; bool IsFull() const; void Enqueue(ItemType item); void Dequeue(ItemType& item); private: int front; int rear; ItemType* items; int maxQue; }; #endif /* QUETYPE_H_ */
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/12/02 11:24