[Boost] Is their any conflicts between boost::thread (and bind...) with inherited methods ?
Is their any probleme with boost::thread and inherited functions ? Here is an example of what doesn't work to me : Class A { public: makeWork() { runThat(); } ; protected: virtual runThat(void); } //A Class B : public A { public : init() { boost::thread(makeWork); }; //v1 init() { boost::thread(boost::bind(B::makeWork)); }; //v2 private : runThat(void) { printf("foo"); }; } No way, once makeWork never run, or with boost::bind, boost::ref, boost::function... I have still errors (do I need to post the errors... ?) That why befor posting any error log, I ask if there are known problems with inheritage and boost::thread ? Of course I know how to use boost::thread and boost::bind, for example if I had this to B, it works Class B : public A { ... public : init2() { boost::thread(foo); }; private : foo(void) { printf("foo"); }; ... } So what ??? In fact, in the real case, B inherit from another class one of my own invention : Singleton<CLASS> no need to explain what it does... maybe the "1 object only" is a problem for boost ? PS : the docs have very few complete examples, do you preview to extend it ? (usage of thread, bind, function, ref in the same example please) monolithic examples are OK to understand the principle, but not to understand complex usages...
"Germain BARRET"
Is their any probleme with boost::thread and inherited functions ?Here is an example of what doesn't work to me :Class A {public:makeWork() { runThat(); } ;protected:virtual runThat(void); } //AClass B : public A {public :init() { boost::thread(makeWork); }; //v1init() { boost::thread(boost::bind(B::makeWork)); }; //v2private :runThat(void) { printf("foo"); };} No way, once makeWork never run, or with boost::bind, boost::ref, boost::function... I have still errors (do I need to post the errors... ?)That why befor posting any error log, I ask if there are known problems with inheritage and boost::thread ? Of course I know how to use boost::thread and boost::bind, for example if I had this to B, it worksClass B : public A {...public :init2() { boost::thread(foo); };private :foo(void) { printf("foo"); }; ...}So what ???In fact, in the real case, B inherit from another class one of my own invention : Singleton<CLASS> no need to explain what it does... maybe the "1 object only" is a problem for boost ? PS : the docs have very few complete examples, do you preview to extend it ? (usage of thread, bind, function, ref in the same example please) monolithic examples are OK to understand the principle, but not to understand complex usages...
If you wish to use a member function with boost::thread or boost::bind, you need to specify which object to call the member function on. e.g. class A { void thread_func(); void run() { boost::thread t(&A::thread_func,this); } }; If thread_func is virtual, this should also work if you pass in an instance of a derived class. Anthony -- Anthony Williams | Just Software Solutions Ltd Custom Software Development | http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL
participants (2)
-
Anthony Williams
-
Germain BARRET