所以我对C++非常陌生,所以原谅我的业余代码。我试图做一个代码,像一个迷你SIRI,其中包含继承类和头文件,但我目前在我的头文件中出现一个奇怪的错误。C++错误“期望不符合标识之前')'标记”(第1行)
这是我在每个文件
的main.cpp
#include <iostream>
#include <string>
#include "JARVIS.h"
using namespace std;
int main()
{
string command;
bool jarvis_running = false;
cout << "J.A.R.V.I.S" << endl;
cout << "Give a command from the list of commands available." << endl;
cin >> command;
if (command == "-h")
{
jarvis_running = true;
cout << "The available commands are: math" << endl;
}
if (command = "math")
{
jarvis_running = true;
math ma;
}
if (jarvis_running == false)
{
cout << "That command was not valid" << endl;
cout << "Type '-h' if you need to know the available commands." << endl;
}
return 0;
}
* JarvisFunctions.cpp
#include <iostream>
#include <string>
#include "JARVIS.h"
using namespace std;
int math()
{
cout << "(A)ddition, (S)ubtraction, (M)ultiplication, or (D)ivision?" << endl;
cin >> mathCommand;
if (mathCommand == "A")
{
cout << "input the two integers you are adding" << endl;
cin >> integer1 >> integer2;
ma.setValues(integer1, integer2);
addition add;
}
else if(mathCommand == "S")
{
cout << "input the two integers you are subtracting" << endl;
cin >> integer1 >> integer2;
ma.setValues(integer1, integer2);
subtraction sub;
}
else if(mathCommand == "M")
{
cout << "input the two integers you are multiplying" << endl;
cin >> integer1 >> integer2;
ma.setValue(integer1, integer2);
mulitplication multi;
}
else if(mathCommand == "D")
{
cout << "input the two integers you are dividing" << endl;
cin >> integer1 >> integer2;
ma.setValues(integer1, integer2);
divions div;
}
else
{
cout << "you did not input the right fuctions, either use A, S, M, or D" << endl;
}
}
JARVIS.h
#ifndef JARVIS_H
#define JARVIS_H
class math
{
private:
int val1;
int val2;
public:
math()
{
cout<<"calling math constructor"<<endl;
}
void setValues (int a, int b){
int a = val1;
int b = val2;
}
~math()
{
cout<<"calling math deconstructor"<<endl;
}
}
class addition:public math
{
int finalVal = val1 + val2;
return finalVal;
};
class subtraction:public math
{
int finalVal = val1 - val2;
return finalVal;
};
class multiplication:public math
{
int finalVal = val1 * val2;
return finalVal;
};
class division:public math
{
int finalVal = val1/val2;
return finalVal;
};
#endif //JARVIS_H
我敢代码肯定还有很多错误与类和我怎么称呼他们,但现在我不知道是什么导致这个错误。
class'math'在关闭'}'后缺少结尾分号。 “数学”的衍生物没有一个是正确的。你把他们当作功能对待;不是课程。 – WhozCraig 2014-12-05 11:00:45
这将有助于完整的编译器日志和用于编译程序的命令,它看起来像某处的语法错误。 – gauteh 2014-12-05 11:00:54
class'addition'也不正确。 – 2014-12-05 11:01:24