I have a defined type and created a list of this type.
Message theMessage;
std::list<Message> LM;
Now this statement
LM.push_back(theMessage);
gives me this error:
/../gcc-4.1.2/lib/gcc/i686-pc-linux-gnu/4.1.0/../../../../include/c++/4.1.0/ext/new_allocator.h:104: error: no matching function for call to ‘
SharedTypes::Message::Message(const SharedTypes::Message&)’
The constructor looks like
explicit Message(Message & aMsg)
{}
How can I fix that?
As was suggested constructor should be:
explicit Message(const Message & aMsg)declared as
publicIf you can’t change this then consider using container of smart pointer, like
std::list<std::shared_ptr<Message>>, orboost::ptr_list<Message>