下面的代碼初始化對象的時候給我「不匹配呼叫」後聲明
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);
...
}
因爲這是我的家庭作業,所以我只發佈了一小段代碼。如果這些還不夠,我可以添加更多。我看到類似的代碼工作,所以我試圖使用它(一些編輯),但它不適合我...
謝謝大家。我是C++的新手,我有點困惑,所以有時我會忘記基本原理。 – milano