26

我从班级中移出方法实现并发现以下错误:

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