我在另一个类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)但是我仍然无法编译。我在这里缺少什么?
感谢。
Chinmay
答案 0 :(得分:2)
根据JesseGood对我的问题的评论,该问题是由于在std::string
中使用MyClass
引起的,这是非常重要的。解决方案是直接在MyClass
而不是boost::lockfree::queue
对象中存储指向MyClass
的指针。