Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could cast the member function pointer to the type you need:</p> <pre><code>mem_fun( static_cast&lt; R (DataStructure::*)( Args... ) &gt;( &amp;DataStructure::top ) ) </code></pre> <p>or</p> <pre><code>mem_fun( static_cast&lt; R (DataStructure::*)( Args... ) const &gt;( &amp;DataStructure::top ) ) </code></pre> <p>with appropriate <code>R</code> for the result type and <code>Args...</code> for the arguments.</p> <p><strong>EDIT:</strong> You made two (three) mistakes in your complete example:</p> <p>a) The cast needs to be exact, that is you need to provide the correct return type. Luckily, <code>std::stack</code> has typedefs to help you with that. In your case, you can cast with these two options:</p> <pre><code>typedef typename DataStructure::reference (DataStructure::*non_const_top)(); mem_fun( static_cast&lt; non_const_top &gt;( &amp;DataStructure::top ) ) </code></pre> <p>or</p> <pre><code>typedef typename DataStructure::const_reference (DataStructure::*const_top)() const; mem_fun( static_cast&lt; const_top &gt;( &amp;DataStructure::top ) ) </code></pre> <p>b) You tried to bind a temporary to a reference when calling <code>ts</code>. Together with a), change the code to:</p> <pre><code>DataStructure ds; typedef typename DataStructure::reference (DataStructure::*non_const_top)(); return ts(tree, value, ds, mem_fun(static_cast&lt;non_const_top&gt;(&amp;DataStructure::top))); </code></pre> <p>c) In <code>ts</code>, you try to call the <code>getter</code> without an object. You need to change it to:</p> <pre><code>auto const current = getter( &amp;ds ); </code></pre> <p>With these changes, the code works for me.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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