{error 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?
问题描述
我在另一个类 MyOuterClass
中有一个结构 MyClass
,我正尝试放入boost :: lockfree :: queue中.我的结构如下图
I have a struct MyClass
inside another class MyOuterClass
I am trying to put into a boost::lockfree::queue. My structure looks like below
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;
,当我尝试编译时会引发以下错误.
My outer class has a public member variable boost::lockfree::queue<MyClass> m_commandQueue;
which throws the following error when I try to compile.
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:错误:静态断言失败:(boost :: has_trivial_destructor< T> :: value)但是我仍然无法编译.我在这里想念什么?
I checked the thread /boost/lockfree/queue.hpp: error: static assertion failed: (boost::has_trivial_destructor<T>::value) however I am still unable to compile. What am I missing here?
谢谢.
钦美
推荐答案
根据JesseGood对我的问题的评论,此问题是由于在 MyClass中使用了
std :: string
这是不平凡的.解决方案是将指向 MyClass
的指针存储在我的 boost :: lockfree :: queue
中,而不是直接将 MyClass
对象存储.
As per JesseGood's comments on my question, the issue was caused due to the use of std::string
in MyClass
which is non-trivial. The solution was to store pointers to MyClass
in my boost::lockfree::queue
instead of MyClass
objects directly.
这篇关于{error C2338:(boost :: has_trivial_destructor< T> :: value)}对boost :: lockfree :: queue意味着什么?我在这里想念什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!