2012-11-20 73 views
16

我搬出從我的類的方法實施,抓住以下錯誤:使用類模板需要模板參數列表

use of class template requires template argument list 

的方法whitch不需要模板類型在所有...(其它方法都可以)

template<class T> 
class MutableQueue 
{ 
public: 
    bool empty() const; 
    const T& front() const; 
    void push(const T& element); 
    T pop(); 

private: 
    queue<T> queue; 
    mutable boost::mutex mutex; 
    boost::condition condition; 
}; 

錯誤執行

template<> //template<class T> also incorrect 
bool MutableQueue::empty() const 
{ 
    scoped_lock lock(mutex); 
    return queue.empty(); 
} 
+6

不相關,但'隊列 queue'是非常奇怪的命名慣例...類型名稱應該是很容易分辨的實例名稱 – relaxxx

+0

我會按照你的建議,但它不是根本原因 – Torrius

回答

34

它應該是:

template<class T> 
bool MutableQueue<T>::empty() const 
{ 
    scoped_lock lock(mutex); 
    return queue.empty(); 
} 

如果你的代碼是短,只是內聯它,因爲你不能無論如何模板類的實現和頭分開。

+0

非常感謝!我現在很清楚 – Torrius

+0

'因爲你無法分開模板類的實現和頭部' Ahhhh .. +1 – Dynite

6

用途:

template<class T> 
bool MutableQueue<T>::empty() const 
{ 
    ... 
} 
相關問題