From: chyujian <iam...@gm...> - 2011-06-09 09:32:46
|
maybe I could describe the problem a bit more specifically, I modified my code this afternoon, and added the -lboost_thread argument specially, but resulted in the same compile fault. This time I attach the compile error message as well, and to my surprise the compiler said the fault was yielded at the last line of the function Move. And this time I paste all my original code at the last of this mail, as well as the compile error. Actually I don't understand what does that error mean, the boost is a bit hard for me. By the way, there is a question I am always wondering: Can I encapsulate the bundles of functions of Player into some subthreads of my own robot class as I currently do? ###.h file### class Robot { private: boost::thread * readThread; public: Robot(); ~Robot(); void Read(); void Move(); }; ### .cc file ### Robot::Robot() { readThread = new boost::thread(&Robot::Read); /* I hope the read task to be implemented in a single independent thread. But once I set up the Read thread, I could not even pass the compile. How can I encapsulate the read task into a single thread? */ } void Robot::Read() { while(true) { /*read data from low level devices, via the robot's PlayerClient object(not explicitly showed in this mail) */ } } void Robot::Move() { /* set the velocity via the position2d device mounted on Robot*/ } ################################################### # hereafter I paste all my original codes and # the compile error: two files compiled by g++ 4.4.5 ################################################### ### the header file RobWen.h ### // Initially by Chyujian // Last modified by Chyujian // Last modi date #include <map> #include <string> #include <vector> using namespace std; #include <boost/thread/thread.hpp> #include <libplayerc++/playerc++.h> using namespace PlayerCc; #ifndef WEN_HEADER #define WEN_HEADER class RobWen { private: PlayerClient *client; Position2dProxy *position2d; SonarProxy *sonar; LaserProxy *laser; boost::thread *readThread; //boost::thread *moveThread; public: RobWen(); ~RobWen(); void Read(); void Move(double lineSpeed); }; #endif // WEN_HEADER ### the RobWen.cc file ### // Initialy by Chyujian // Last modified by Chyujian // Lsst modidate #include <iostream> using namespace std; #include <boost/thread/thread.hpp> #include "RobWen.h" RobWen::RobWen() { client = new PlayerClient("localhost", 6665); position2d = new Position2dProxy(client, 0); sonar = new SonarProxy(client, 0); laser = new LaserProxy(client, 0 ); readThread = new boost::thread(&RobWen::Read); } RobWen::~RobWen() { delete laser; delete sonar; delete position2d; delete client; delete readThread; } void RobWen::Read() { while(true) { RobWen::client->Read(); } return; } void RobWen::Move(double lineSpeed) { RobWen::position2d->SetSpeed(lineSpeed, 0 , 0); return; } ### compile command and error message ### g++ -c -o RobWen_edit RobWen_edit.cc -lboost_thread `pkg-config --cflags --libs playerc++` In file included from /usr/include/boost/thread/thread.hpp:22, from RobWen.cc:7: /usr/include/boost/thread/detail/thread.hpp: In member function ‘void boost::detail::thread_data<F>::run() [with F = void (RobWen::*)()]’: RobWen.cc:44: instantiated from here /usr/include/boost/thread/detail/thread.hpp:56: error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘((boost::detail::thread_data<void (RobWen::*)()>*)this)->boost::detail::thread_data<void (RobWen::*)()>::f (...)’, e.g. ‘(... ->* ((boost::detail::thread_data<void (RobWen::*)()>*)this)->boost::detail::thread_data<void (RobWen::*)()>::f) (...)’ |