求排错,用了boost::mutex之后就编译不过
- #include <iostream>
- #include <deque>
- using namespace std;
- #include <boost/thread/thread.hpp>
- // 基本消息对象
- typedef struct
- {
- int messageId; // 若Id为0则为无效消息
- }RobotMessage;
-
- // 消息对列对象
- class RobotMessageQueue
- { // 编译错误说的第17行
- private:
- // 消息对了未定义
- boost::mutex messageQueueMutex; // 用来保护消息对列的读写,就是加上这句总是编译不过
- public:
- void AppendMessage(RobotMessage message); // 消息入队
- void ProvideMessage(RobotMessage * message);// 消息出队
- };
-
- void RobotMessageQueue::AppendMessage(RobotMessage message)
- {
-
- //boost::mutex::scoped_lock lock(this->messageQueueMutex);
- return;
- }
-
- void RobotMessageQueue::ProvideMessage(RobotMessage * message)
- {
- //boost::mutex::scoped_lock lock(this->messageQueueMutex);
- // ....
- return;
- }
-
- class RobWen // 机器人对象
- {
- private:
- RobotMessageQueue speakMessageQueue;
- boost::thread *sensingThread; // 一个感知线程
- boost::thread *speakingThread; // 一个语音线程
-
- public:
- RobWen();
- ~RobWen();
- void Read(); // 感知线程函数,发送消息入队
- void Speak(); // 语音线程函数,提取消息出队
-
- };
-
-
- RobWen::RobWen()
- {
- sensingThread = new boost::thread(boost::bind(&RobWen::Read, this));
-
- speakMessageQueue = RobotMessageQueue(); // 这一句也总是报错,编译错误说的第57行
- speakingThread = new boost::thread(boost::bind(&RobWen::Speak, this));
- }
-
- RobWen::~RobWen()
- {
- delete sensingThread;
- delete speakingThread;
- }
-
- void RobWen::Read()
- {
- while(true)
- {
-
- RobotMessage message;
- message.messageId = 1;
- speakMessageQueue.AppendMessage(message);
- }
-
- return;
- }
-
-
- void RobWen::Speak()
- {
-
- while(true)
- {
- // handle the message
- RobotMessage message;
- this->speakMessageQueue.ProvideMessage(&message);
- if(message.messageId != 0)
- {
- cout << "收到消息,Id:" << message.messageId << endl;
- }
- }
-
- }
- g++ -c -o errorTest RobWen2_edit.cc
- In file included from /usr/include/boost/thread/mutex.hpp:16,
- from /usr/include/boost/thread/pthread/thread_data.hpp:12,
- from /usr/include/boost/thread/thread.hpp:17,
- from RobWen2_edit.cc:8:
- /usr/include/boost/noncopyable.hpp: In member function ‘boost::mutex& boost::mutex::operator=(const boost::mutex&)’:
- /usr/include/boost/noncopyable.hpp:28: error: ‘const boost::noncopyable_::noncopyable& boost::noncopyable_::noncopyable::operator=(const boost::noncopyable_::noncopyable&)’ is private
- /usr/include/boost/thread/pthread/mutex.hpp:31: error: within this context
- RobWen2_edit.cc: In member function ‘RobotMessageQueue& RobotMessageQueue::operator=(const RobotMessageQueue&)’:
- RobWen2_edit.cc:17: note: synthesized method ‘boost::mutex& boost::mutex::operator=(const boost::mutex&)’ first required here
- RobWen2_edit.cc: In constructor ‘RobWen::RobWen()’:
- RobWen2_edit.cc:57: note: synthesized method ‘RobotMessageQueue& RobotMessageQueue::operator=(const RobotMessageQueue&)’ first required here
作者: trypsin 发布时间: 2011-06-13
g++ -c -o errorTest RobWen2_edit.cc -pthread
作者: int-main 发布时间: 2011-06-13