{错误 C2338: (boost::has_trivial_destructor:<T>:value)} 对于 boost::lockfree::queue 是什么意思?我在这里错过了什

What does {error C2338: (boost::has_trivial_destructor<T>::value)} mean for boost::lockfree::queue ? What am I missing here?

本文关键字:boost queue lockfree 对于 是什么 错过了 意思 在这里 has C2338 错误      更新时间:2023-10-16

我在另一个类MyOuterClass中有一个结构体MyClass,我试图放入boost::lockfree::队列。我的结构如下

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 "x64DebugMDServices.unsuccessfulbuild".
1>ClCompile:
1>  MyOuterClass.cpp
1>C:localboost_1_53_0boost/lockfree/queue.hpp(79): error C2338: (boost::has_trivial_destructor<T>::value)
1>          srcMyOuterClass.cpp(70) : see reference to class template instantiation 'boost::lockfree::queue<T>' being compiled
1>          with
1>          [
1>              T=MDServices::MyClass
1>          ]
1>C:localboost_1_53_0boost/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:错误:静态断言失败:(boost::has_trivial_destructor::value)但是我仍然无法编译。我遗漏了什么?

谢谢。

Chinmay

根据JesseGood对我的问题的评论,这个问题是由于在MyClass中使用std::string引起的,这是不平凡的。解决方案是将指向MyClass的指针直接存储在我的boost::lockfree::queue而不是MyClass对象中。