2011-12-21 10 views
1

テンプレートのQueueクラスを作成しようとしています。それは大丈夫だと思うが、なぜ私は理由を理解できない同じ行に2つのエラーが発生しています。このエラーは、デストラクタの定義を与えようとしている実装ファイル.cppに現れます。私はエラーが上記指摘されているエラー: '<'トークンの前にunqualified-idが必要です。

#include "QueueTp.h" 
#include <iostream> 

using namespace std; 

typename <class T> //<-<-<- in this line I am getting the two errors 
QueueTp<class T>::~QueueTp() 
{ 
    Node *ptr; 
    cout<<endl<<"Deleting the queue..."; 
    while (head !=NULL) 
    { 
     ptr = head->next; 
     delete head; 
     head = ptr; 
    } 
} 

//......other method definitions 

と特定のエラーメッセージ:

#ifndef QUEUETP_H_INCLUDED 
#define QUEUETP_H_INCLUDED 

template <class T> 
class QueueTp 
{ 
    private: 
     struct Node { T item; struct Node * next;}; 
     enum {QSIZE = 10}; 
     //Queue's head 
     Node *head; 
     //Queue's tail 
     Node *tail; 
     int size; 
     int maxsize; 
     QueueTp(const QueueTp & q); 
     QueueTp & operator=(const QueueTp & q) { return *this;} 

    public: 
     QueueTp(): size(0),head(0),tail(0),maxsize(QSIZE) {}; 
     QueueTp(int q = QSIZE): size(0),head(0),tail(0),maxsize(q) {}; 
     ~QueueTp(); 
     bool isEmpty(){return size==0;} 
     bool isFull() {return size==maxsize;} 
     int sizecur() {return size;} 
     bool push(const T& t); 
     bool pop(T& t); 
}; 

#include "QueueTp.cpp" 
#endif // QUEUETP_H_INCLUDED 

そして、ここでは、デストラクタの定義は、実装ファイルにあります。ここでは、クラスのヘッダファイルのコードがありますコンパイラから取得するには以下のものがあります。

error: expected nested-name-specifier before ‘<’ token| 
error: expected unqualified-id before ‘<’ token| 
||=== Build finished: 2 errors, 12 warnings ===|| 
+1

'template QueueTp ::〜QueueTp()' – ildjarn

+0

どういうわけかその愚かな質問を削除できますか?私は戸惑いを感じます。 –

+0

はい、質問の末尾に「削除」リンクがあります。 : - ] – ildjarn

答えて

2

2つのエラーメッセージが表示されている行に "typename"の代わりに "template"を使用してください。ほとんどの場合、未確認のキーワードや間違った場所にある実際のキーワードは、定義されていないタイプに似たエラーを表示することがあります。エラーが発生すると、次のシンボルが表示されます。

関連する問題