26

メソッドの実装をクラスから移動したところ、次のエラーが発生しました。

use of class template requires template argument list

テンプレートタイプをまったく必要としないメソッドの場合...(他のメソッドの場合はすべて問題ありません)

クラス

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();
}
4

2 に答える 2

44

そのはず:

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

また、コードがそれほど短い場合は、テンプレート クラスの実装とヘッダーを分離できないため、インライン化するだけです。

于 2012-11-20T16:03:01.670 に答える
6

使用する:

template<class T>
bool MutableQueue<T>::empty() const
{
    ...
}
于 2012-11-20T16:04:14.880 に答える