所以我對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