每当我编译这个程序时,我都会收到一条错误消息“第 13 行的 decleration 类型太多”。我没有看到任何可能的语法错误,但我仍然面临这个问题。
#include<iostream.h>
#include<conio.h>
class currency
{
private:
int rupee,paise;
int total;
public:
void getdata(int r,int p);
void display();
}
void currency::getdata(int r, int p){
rupee=r;
paise=p;
total=r*100+p;
}
void currency::display(){
cout<<rupee<<" Rupees"<<" and "<<paise<<"Paise"<<endl;
cout<<"Converted value="<<total;
}
int main(){
currency c;
c.getdata(5,25);
c.display();
getch();
return 0;
}
原文由 Adarsh Hegde 发布,翻译遵循 CC BY-SA 4.0 许可协议
需要有一个分号来终止类定义:
否则,编译器看起来像这样: