我试图编译这段代码,我没有收到任何抱怨。但是,当我运行它时,它给了我最后一行的异常错误,即 cout<<"Norm:"<
你能指导我如何解决这个问题。先感谢您
#include <stdafx.h>
#include <iostream>
#include <string>
#include <boost/function.hpp>
#include <boost/array.hpp>
using namespace std;
template<typename R,typename D>
class GenericFunction
{
private:
boost::function<R (D)> f;
protected:
GenericFunction(){};
public:
GenericFunction(const boost::function<R (D)>& myFunction){f=myFunction;};
R evaluate(const D& value) const{cout<<"Good Job"<<endl;} ;
R operator ()(const D& value);// const{ return f(value); };
};
template <typename R, typename D, int N>
class ScalarValuedFunction:public GenericFunction<R,boost::array<D, N>>
{
public:
ScalarValuedFunction(const boost::function<R (const boost::array<D, N>)> &myF){};
};
template<typename Numeric, std::size_t N>
Numeric Norm(const boost::array<Numeric , N>& Vec)
{
Numeric Result=Vec[0]*Vec[0];
for (std::size_t i=1; i<Vec.size();i++)
{
Result+=Vec[i]*Vec[i];
}
return Result;
}
double test(double t)
{
return t;
}
int main ()
{
const int N=4;
boost::array<double, N> arr={0.2, .3, 1.1, 4};
ScalarValuedFunction<double, double, N> myfun(Norm<double,N>);
cout<<"Norm:"<<myfun(arr)<<endl;
}