2

MyClass我在另一个类中有一个结构,MyOuterClass我试图将其放入 boost::lockfree::queue 中。我的结构如下所示

struct MyClass
{
    MyClass() {}
    MyClass(const string& topic, const string& multicastChannel, const string& netInterface, MyOuterClass::MY_COMMAND_ENUM command, MyOuterClass::CallbackType callback)
    :topic(topic), multicastChannel(multicastChannel), netInterface(netInterface), command(command), callback(callback) {}

    MyClass(const MyClass& src)
    :topic(src.topic), multicastChannel(src.multicastChannel), netInterface(src.netInterface), command(src.command), callback(src.callback) {}
    MyClass& operator=(const MyClass& src)
    {
        topic = src.topic;
        multicastChannel = src.multicastChannel;
        netInterface = src.netInterface;
        command = src.command;
        callback = src.callback;
    }

    ~MyClass(){}

    string topic;
    string multicastChannel;
    string netInterface;
    MyOuterClass::MY_COMMAND_ENUM command;
    MyOuterClass::CallbackType callback;
};

我的外部类有一个公共成员变量boost::lockfree::queue<MyClass> m_commandQueue;,当我尝试编译时会引发以下错误。

1>------ Build started: Project: MDServices, Configuration: Debug x64 ------
1>Build started 6/10/2013 4:41:00 PM.
1>InitializeBuildStatus:
1>  Touching "x64\Debug\MDServices.unsuccessfulbuild".
1>ClCompile:
1>  MyOuterClass.cpp
1>C:\local\boost_1_53_0\boost/lockfree/queue.hpp(79): error C2338: (boost::has_trivial_destructor<T>::value)
1>          src\MyOuterClass.cpp(70) : see reference to class template instantiation 'boost::lockfree::queue<T>' being compiled
1>          with
1>          [
1>              T=MDServices::MyClass
1>          ]
1>C:\local\boost_1_53_0\boost/lockfree/queue.hpp(83): error C2338: (boost::has_trivial_assign<T>::value)
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:03.38
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我检查了线程/boost/lockfree/queue.hpp: error: static assertion failed: (boost::has_trivial_destructor<T>::value)但是我仍然无法编译。我在这里想念什么?

谢谢。

钦梅

4

1 回答 1

2

根据 JesseGood 对我的问题的评论,该问题是由于使用std::stringin MyClasswhich is non-trivial 引起的。解决方案是将指针直接存储MyClass在 myboost::lockfree::queue而不是MyClass对象中。

于 2013-06-10T21:36:29.290 回答