0

私がコメントした行に対してこのエラーを生成する以下のクラスがあります: ' 解決策を探そうとすると混乱します。

フォワード オイラーのシグネチャは次のとおりです。

Eigen::MatrixXd Forward_Euler(double (*f)(double), double (*gleft)(double), double (*gright)(double))

そして私のクラスは次のとおりです。

class C
{
protected:
    A x;
    B y;
    double a;
    double b;
    Eigen::MatrixXd u;

public:
    double f(double x)
    {
        return a;
    }
    double gleft(double tau)
    {
        return b
    }
    double gright(double tau)
    {
        return a*b;
    }
    FD_Euro_Put(): x(), y(), a(0), b(0){}
    FD_Euro_Put(char y1, double y2, double y3, double y4, double x2,
            double x3, double x4, double x5, double x6, double x7):
            x(x1, x2, x3, x4, x5, x6, x7)
    {
        double Xleft = x1*x2;
        double Xright = x1*x3;
        double Tauf = x1*x1;
        double NN = floor((x1/x2);
        a = x1*x2 - 0.5;
        b = x1*x2 + 0.5;

        pde = HeatPDE(y1, NN, Xleft, Xright, Tauf, Alpha); //begin problem area
        u.resize(pde.N+1, pde.M+1); 
        if(fdtype == 'f')
            u = pde.Forward_Euler(&f, &gleft, &gright);
        else if(fdtype == 'b')
            u = pde.Backward_Euler(&f, &gleft, &gright);
        else if(fdtype == 'c')
            u = pde.Crank_Nicolson(&f, &gleft, &gright); //end problem area
        else
            cout << "Incorrect choice for finite difference type!" << endl;
    }
4

1 に答える 1

3

メンバー関数ポインターと関数ポインターは同じものではありません。メンバー関数ポインターの仕事ははるかに難しく、仮想関数やthisポインターなどを処理する必要があります。

しかし、あなたのクラスの関数を見てください! オブジェクトから何も使用しないため、実際にはオブジェクト関数ではありません。それらをクラスの外に移動するか、クラスのstatic関数にすることができます。これらのいずれかを行うと、それらを関数ポインターとして使用できます。

クラス テンプレートと静的関数を使用する必要があると思います。引数をテンプレート引数として指定できます。

于 2012-12-06T20:56:06.253 に答える