以下代码给了我

test2.cc:248:14: error: no match for call to '(Integrator) (Input, double)'
test2.cc:249:11: error: no match for call to '(Integrator) (Integrator&, double)'


在编译。

class Integrator : public Block {
    private:
            ...
        Input input;
        double init_value;
    public:
        Integrator();
        Integrator(Input i, double initval = 0) : input(i), init_value(initval) {}
        Integrator(Integrator &i, double initval = 0) : input(i), init_value(initval) {}
...
};

// + is overloaded
Input operator + (Input a, Input b) { return new Add(a,b); }

int main() {
    Constant a(4.0); // Input
    Integrator x,y;
    ...
    x(y + a, 0.0); // + is overloaded for Inputs
    y(x, -2.0);
    ...
}


我只发布部分代码,因为这是我的作业。如果这些还不够,我可以添加更多。我看到类似的代码可以正常工作,因此我尝试使用它(进行了一些编辑),但对我而言不起作用...

最佳答案

声明对象后就无法对其进行初始化。 x()尝试调用x作为函数。

关于c++ - 声明后初始化对象时,“调用不匹配”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13703202/

10-11 22:28
查看更多