Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You cannot pass a member function pointer as a function pointer, because the latter lacks the context pointer (the <code>this</code>) to properly invoke the member function pointer.</p> <p>The general way to solve this (as in the standard C++ library) is to use a template:</p> <pre><code>template &lt;typename F&gt; double OneDimBisector(F fun, float a, float b, float tol){ double val; val = fun(0.5*(b-a)); return val; } </code></pre> <p>and pass a function object to it</p> <pre><code>struct Evaluator { EOS* this_; Evaluator(EOS* this_) : this_(this_) {} // constructor double operator()(double value) const // call the function { return this_-&gt;functForT_PS(value); } }; T1 = OneDimBisector(Evaluator(this), Tmin, Tmax, tol); </code></pre> <p>You could also use <code>std::bind1st(std::mem_fun(&amp;EOS::functForT_PS), this)</code>, but what it does is just the same as the structure above. <sub><sup>(BTW, both std::bind1st and std::mem_fun have been deprecated.)</sup></sub></p> <p>If you don't like templates, you could accept a polymorphic function instead (e.g. using <a href="http://www.boost.org/doc/libs/1_48_0/doc/html/function.html" rel="nofollow">Boost.Function</a> or std::function in C++11), but it will be slower:</p> <pre><code>double OneDimBisector(const boost::function&lt;double(double)&gt;&amp; fun, float a, float b, float tol) { return fun(0.5 * (b-a)); } </code></pre> <p>and finally, if you can use C++11, you could use a lambda function on calling OneDimBisector:</p> <pre><code>T1 = OneDimBisector([=](double value){ return functForT_PS(value); }, Tmin, Tmax, tol); </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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