问题
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;
};
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 ==========
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?
Thanks.
Chinmay
回答1:
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.
来源:https://stackoverflow.com/questions/17032725/what-does-error-c2338-boosthas-trivial-destructortvalue-mean-for-boos