我的新程序有一点小问题。我制作了一个班级档案,直到一切顺利!我明白了!
C:\Code Block Projects\Not so Advanced Calculator\Calcu.cpp|5|error: expected lified-id before '{' token|
在代码块 12.11 中;
我的Calcu.h 文件:
#ifndef CALCU_H
#define CALCU_H
class Calcu
{
public:
Calcu();
};
#endif // CALCU_H
我的Calcu.cpp 类文件:
#include "Calcu.h"
#include <iostream>
using namespace std;
Calcu{
Calcu(){}
public:
void setNumbers(int x, int y){ no1=x, no2=y; }
int getAddition() {return no1+no2;}
int getSubstraction() {return no1-no2;}
int getDivision() {return no1/no2;}
int getMultiplication() {return no1*no2;}
int getExponent(){ return no1**no2; }
private:
int no1, no2;
};
还有我的 main.cpp:
#include <iostream>
#include <Calcul.h>
using namespace std;
void function_calculator()
{
Calcu calcul;
int noI, noII; char operation;
cout << "Welcome to a more advanced and optimized calculator. ©UnityInc." << endl;
cout << "Please insert your desired numbers. First number should be carefully selected if you wish to raise to the exponent.";
cin>>noI;
cout<<"Great, now insert your other number: ";
cin>>noII;
calcu.setNumbers(noI, noII);
cout<<"Very well, what kind of operation would you like? +, -, *, / or exponantiation(type **): ";
cin>>operation;
if(operation=='+')
calcul.getAddition();
else if(operation=='-')
calcul.getSubstraction();
else if(operation=='/')
calcul.getDivision();
else if(operation=='*')
calcul.getMultiplication();
else if(operation=='**')
calcul.getExponent();
else
return function_calculator;
}
int main()
{
function_calculator;
return 0;
}
任何帮助将非常感激!