Так что я действительно новичок в 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
Я довольно конечно, все еще много чего с классом и как я их называю, но пока я не уверен, что вызывает эту ошибку.
Класс 'math' не имеет своей закрывающейся запятой после закрытия'} '. И ни одна из производных от «математики» не верна. Вы обращаетесь с ними так, как будто это функции; не классы. – WhozCraig
Было бы полезно с полным журналом компилятора и командой, которую вы используете для компиляции вашей программы, она выглядит как синтаксическая ошибка где-то. – gauteh
Неверный класс 'дополнение'. –