[英]use of class template requires template argument list
我从我的类中移出了方法实现并捕获了以下错误:
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();
}
它应该是:
template<class T>
bool MutableQueue<T>::empty() const
{
scoped_lock lock(mutex);
return queue.empty();
}
如果您的代码很短,只需内联它,因为您无法分离模板类的实现和标头。
采用:
template<class T>
bool MutableQueue<T>::empty() const
{
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.