Boost logo

Boost Users :

Subject: Re: [Boost-users] [thread] About the virtual in virtual operator()
From: Nigel Rantor (wiggly_at_[hidden])
Date: 2009-10-31 17:14:39


Richard Vock wrote:
>> The smallest change to your code I think would be this
> though.
>> ---
>> thread t( boost::bind( &Kernel::operator(), m_kernel[i] )
> );
>> t.join();
>
> I've always had problems understanding boost::bind, but this
> helps a lot.
>
> And it works too...
>
> Thank you!

I realise this solves your problem but didn't really answer your
question though.

The reason it doesn't work with an abstract class is because the thread
class attempts to copy the functor you're passing in. Since Kernel is
abstract you can't do this.

If you make Kernel a concrete class you get a different problem.

The statement:

thread t( *(m_kernel[i]) )

slices the object down to a plain old Kernel, irrespective of what the
pointer originally referenced.

You can only call virtual functions through pointers or references so
you lose dynamic binding once this happens.

   n


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net