Note that there are some explanatory texts on larger screens.

plurals
  1. POException in template
    primarykey
    data
    text
    <p>I tried to compile this code and I receive no complain. However, when I run it , it give me an exception error for the last line i.e. cout&lt;&lt;"Norm:"&lt; <p>Could you please guide me how I can solve this problem. Thank you in advance</p> <pre><code>#include &lt;stdafx.h&gt; #include &lt;iostream&gt; #include &lt;string&gt; #include &lt;boost/function.hpp&gt; #include &lt;boost/array.hpp&gt; using namespace std; template&lt;typename R,typename D&gt; class GenericFunction { private: boost::function&lt;R (D)&gt; f; protected: GenericFunction(){}; public: GenericFunction(const boost::function&lt;R (D)&gt;&amp; myFunction){f=myFunction;}; R evaluate(const D&amp; value) const{cout&lt;&lt;"Good Job"&lt;&lt;endl;} ; R operator ()(const D&amp; value);// const{ return f(value); }; }; template &lt;typename R, typename D, int N&gt; class ScalarValuedFunction:public GenericFunction&lt;R,boost::array&lt;D, N&gt;&gt; { public: ScalarValuedFunction(const boost::function&lt;R (const boost::array&lt;D, N&gt;)&gt; &amp;myF){}; }; template&lt;typename Numeric, std::size_t N&gt; Numeric Norm(const boost::array&lt;Numeric , N&gt;&amp; Vec) { Numeric Result=Vec[0]*Vec[0]; for (std::size_t i=1; i&lt;Vec.size();i++) { Result+=Vec[i]*Vec[i]; } return Result; } double test(double t) { return t; } int main () { const int N=4; boost::array&lt;double, N&gt; arr={0.2, .3, 1.1, 4}; ScalarValuedFunction&lt;double, double, N&gt; myfun(Norm&lt;double,N&gt;); cout&lt;&lt;"Norm:"&lt;&lt;myfun(arr)&lt;&lt;endl; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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. 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