Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy can't I use a boost::function in an Objective-C++ block?
    primarykey
    data
    text
    <p>The following code throws an exception</p> <pre><code>terminate called after throwing an instance of 'boost::exception_detail::clone_impl&lt;boost::exception_detail::error_info_injector&lt;boost::bad_function_call&gt; &gt;' what(): call to empty boost::function </code></pre> <p>at the line <code>f()</code> (while executing the block):</p> <pre><code>void foo(); // assume this is defined somewhere boost::function&lt;void()&gt; f = boost::bind(&amp;foo); ^(void) { f(); }(); </code></pre> <p>However, according to <a href="http://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Blocks/Blocks.pdf" rel="nofollow">the documentation on blocks</a>,</p> <blockquote> <p>In general you can use C++ objects within a block. Within a member function, references to member variables and functions are via an implicitly imported this pointer and thus appear mutable. There are two considerations that apply if a block is copied:</p> <ul> <li><p>If you have a __block storage class for what would have been a stack-based C++ object, then the usual copy constructor is used.</p></li> <li><p>If you use any other C++ stack-based object from within a block, it must have a const copy constructor. The C++ object is then copied using that constructor.</p></li> </ul> </blockquote> <p>This seems to be true normally; if I replace <code>f</code> above with an instance of a simple class with an <code>operator()()</code>, the above code runs as expected.</p> <p>Why doesn't the version with <code>boost::function</code> work?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload