把類和實現(xiàn)分開寫,再寫一個主函數(shù),編譯無錯,但運行出現(xiàn)問題。將頭文件后綴改后這也是從CSDN搜到的解決方法,不知道具體原因,求問。代碼列下queue.htemplate<class?T>
class?Queue
{
public:
?virtual?bool?IsEmpty()?const?=?0;
?virtual?bool?IsFull()??const?=?0;
?virtual?bool?Front(T&?x)?const?=?0;
?virtual?bool?EnQueue(T?x)?=?0;
?virtual?bool?DeQueue()?=?0;
?virtual?void?Clear()?=?0;
};SetQueue.h#include"queue.h"
template<class?T>
class?SeqQueue?:
?public?Queue<T>
{
public:
?SeqQueue(int?mSize);
?~SeqQueue()?{?delete[]?q;?}
?bool?IsEmpty()?const?{?return?front?==?rear;?}
?bool?IsFull()?const?{?return?(rear?+?1)?%?maxSize?==?front;?}
?bool?Front(T&?x)?const;
?bool?EnQueue(T?x);
?bool?DeQueue();
?void?Clear()?{?front?=?rear?=?0;?}
private:
?int?front,?rear;
?int?maxSize;
?T?*q;
};SetQueue.cpp#include"SetQueue.h"
template<class?T>
SeqQueue<T>::SeqQueue(int?mSize)
{
?maxSize?=?mSize;
?q?=?new?T[maxSize];
?front?=?rear?=?0;
}
template<class?T>
bool?SeqQueue<T>::Front(T?&?x)?const
{
?if?(IsEmpty())
?{
??cout?<<?"empty"?<<?endl;
??return?false;
?}
?x?=?q[(front?+?1)?%?maxSize];
?return?true;
}
template<class?T>
bool?SeqQueue<T>::EnQueue(T?x)
{
?if?(IsFull())
?{
??cout?<<?"Full"?<<?endl;
??return?false;
?}
?q[(rear?=?(rear?+?1)?%?maxSize)]?=?x;
?return?true;
}
template<class?T>
bool?SeqQueue<T>::DeQueue()
{
?if?(IsEmpty())
?{
??cout?<<?"Underflow"?<<?endl;
??return?false;
?}
?front?=?(front?+?1)?%?maxSize;
?return?true;
}
LNK2019,為什么直接將.h改成.cpp后就能生成解決方案成功
小塵子
2018-05-30 17:27:26