1

I've a class with [] operator overloaded. I also have a thread to start... How can I bind [] to the thread?

I tried this:

threadpool.schedule( bind( static_cast< MyClass (MyClass::*)(const MyClass &arg )>( &MyClass::operator[]), arg ) )

but VS2008 says:

error C2664:

'boost::threadpool::thread_pool::schedule': cannot convert parameter 1 from 'boost::_bi::bind_t' to 'const boost::function0 &'

How can i resolve this? Thank you in advance.

Sam
  • 11
  • 1

1 Answers1

1

That looks wrong. Your member function still accepts one argument. So you need a placeholder, or you forgot to bind this

threadpool.schedule( bind( 
  static_cast< MyClass (MyClass::*)(const MyClass &arg )>(&MyClass::operator[]), 
  this, arg ) ) 

An operator[] that accepts its class type looks a bit weird though. Here is an example how it should look for a "usual" subscript operator

threadpool.schedule( bind(
  static_cast< MyClass (MyClass::*)(std::size_t)>(&MyClass::operator[]), this, index ) 
); 
Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212