我的计划是制作一个简单的加法计算器,然后继续前进。请记住,这是我编码的第一天。
#include <iostream>
#include <string>
using namespace std;
int a;
int b;
int sum;
string ans;
class CalcClass{
public:
int add (int a, int b) {
cout << "Pick the numbers you want to add" << endl;
cin >> a >> b;
sum = a + b;
return sum;
}
};
添加string ans;
(在顶部)。现在我得到一个"error: no matching function for call to 'CalcClass::add()'"
calcObject
如果我已经创建并用于calcObject.add();
调用该函数,为什么会这样说?
void pickFunction(){
cout << "What Function do you want to do? \n Add, Subtract, multiply, or divide? ";
cin >> ans;
if (ans == "add"){
CalcClass calcObject;
calcObject.add();
}
int main(){
pickFunction();
cout << "Your answer is : " << sum << endl;
return 0;
}