Hi
jean.daniel.mich@gmail.com schreef:
> I am using a class with operator() as threadfunc for Boost.Thread. I
> have inheritance used with those class but it does not work, see the
> example:
[includes, class Bird, class Swan snipped]
> int main()
> {
> Swan mySwan;
> Bird* myBird = &mySwan;
> Bird *b = &mySwan;
> boost::thread thrd(*b);
From the boost documentation:
| class thread : private boost::noncopyable // Exposition only
| {
| public:
| // construct/copy/destruct
| thread();
| explicit thread(const boost::function0<void>&);
| ~thread();
and
| template<typename F> functionN(F f);
| Requires: F is a function object Callable from this.
| Postconditions: *this targets a copy of f if f is nonempty, or
| this->empty() if f is empty.
So effectively you create a boost::function0<Bird> object that _copies_
*b (slicing!). You then create a boost::thread object from that.
Avoid the copy by using an additional indirection, e.g. consider
boost::ref :
boost::thread thrd( boost::ref(*b) );
Markus