I have he following interface:
template <class T>
class AbstractTask {
public:
virtual void BindTaskCompleted(AbstractTask<T> &bindedTask)=0;
virtual void Join(TaskResult<T>)=0;
};
And the following implentation:
template <class T>
class SlaveTask: public AbstractTask<T> {
public:
typedef boost::function<void(TaskResult<T>)> joinFunction;
void BindTaskCompleted(AbstractTask<T> &bindedTask)
{
/////////////WORK OK//////////////////////////////
//bindedTask.Join(result);
/////////////COMPILATION ERROR/////////////////////
slaveTaskCompletionFunction=boost::bind(&AbstractTask<T>::Join,bindedTask,result);
}
void Join(TaskResult<T> r)
{
slaveTaskCompletionFunction(r);
}
private:
joinFunction slaveTaskCompletionFunction;
TaskResult<T> result;
};
I’m trying to bind the virtual Join Method of a AbstractTask implementation to a boost::function with the same signature. boost::bind throws 77 compilation errors and I fail to see why.
I thought at first that boost::bind couldn’t be use with virtual method but this doesn’t seem to be the case:
Virtual function and boost bind strange behavior
Thanks in advance for your help!
Thomas
The problem is you’ve bound all of the arguments, but the
boost::functionand how you’re using it typedef indicates it wants 1 argument.Change it to the following.
slaveTaskCompletionFunction=boost::bind(&AbstractTask<T>::Join,&bindedTask,_1);Edit: Also, you had a slicing problem when you passed in bindedTask by reference. You either have to pass it in by pointer, or use
boost::ref; otherwise,boost::bindattempts to make a copy of theAbstractTask<T>, and will end up only copying the interface.