从自己的类型创建boost :: lockfree :: queue时出错

时间:2014-01-02 19:00:09

标签: c++ boost queue

我正在尝试使用自己声明的类型的boost :: lockfree:queue创建一个Queue。我检查了Class template for queue的要求:

  • T必须有一个复制构造函数
  • T必须有一个简单的赋值运算符
  • T必须有一个简单的析构函数

所以我实现了以下类:

namespace ek {
class SourceQueueElement{
    private:
        int id;
        std::string fileName;
    public:
        SourceQueueElement(int id, std::string fileName);
        SourceQueueElement(const SourceQueueElement &rhs);
        SourceQueueElement& operator=(const SourceQueueElement& rhs);
        ~SourceQueueElement();
        int getId();
        void setId(int id);
        std::string getFileName();
        void setFileName(std::string fileName);
};}

并实施了方法:

#include "sourcequeueelement.h"

ek::SourceQueueElement::SourceQueueElement(int id, std::string fileName){
    this->id = id;
    this->fileName = fileName;
}

ek::SourceQueueElement::SourceQueueElement(const ek::SourceQueueElement &rhs){
    this->setFileName(rhs.getFileName());
    this->setId(rhs.getId());
}

ek::SourceQueueElement::~SourceQueueElement(){
    this->id = 0;
    this->fileName = null;
}

ek::SourceQueueElement& operator=(const ek::SourceQueueElement &rhs){
    this->setFileName(rhs.getFileName());
    this->setId(rhs.getId());
    return *this;
}

我认为方法实现非常简单。问题是,尝试在boost :: lockfree_queue中使用该类失败:

boost::lockfree::queue<ek::SourceQueueElement> sourceQueue(256);

出现以下错误:

/usr/include/boost/lockfree/queue.hpp:87:5: error: invalid application of 'sizeof' to incomplete type 'boost::STATIC_ASSERTION_FAILURE<false>'
 BOOST_STATIC_ASSERT((boost::has_trivial_destructor<T>::value));

/usr/include/boost/lockfree/queue.hpp:91:5: error: invalid application of 'sizeof' to incomplete type 'boost::STATIC_ASSERTION_FAILURE<false>'
 BOOST_STATIC_ASSERT((boost::has_trivial_assign<T>::value));

我知道根据this Stack Overflow question,如果不符合队列要求,则会发生此错误。例如。如果你尝试使用std :: string作为T来进行boost :: lockfree:queue。但我想我已经在课堂上实现了所需的方法。有人知道哪个是问题,还是我误解了要求?

感谢您的帮助。

0 个答案:

没有答案