• 12
• 11
• 9
• 10
• 13

# Assignment operator/copy constructor issue with Boost.Function

This topic is 2112 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've scoured the internet for hours on this one and still cannot figure it out! Any help is appreciated.

 typedef boost::function<void ()> TaskKernel; void TaskScheduler::pushTask(const TaskData& taskData, TaskKernel kernel) { Task* task = m_taskPool->obtain(); task->m_kernel = TaskKernel(kernel); task->m_taskData = taskData; } // later in the calling code sch->pushTask(TaskData(), boost::bind(&run); 

I get an EXC_BAD_ACCESS in boost move_assign function for the copy constructor or operator= every time. I tried passing the function without boost::bind and with all different variations. No luck...

Is there a special technique I am missing for passing boost::functions around? Edited by Craig_jb

##### Share on other sites
Perhaps try changing this:

 // task->m_kernel = TaskKernel(kernel); task->m_kernel = kernel; 

I haven't looked at the latest code for boost::function, but if it's doing move-emulation for your non-C++11 compiler, that might be causing trouble. If you really need the extra copy, try copying it to a named temporary prior to the assignment (making the source of the assignment an l-value).

EDIT: perhaps you also intended to use pass-by-const-reference for the 'kernel' argument in pushTask()? Though I don't think that will cause this problem. Edited by e?dd