声明终止cpp中的以下代码中出现错误

Declaration terminated Incorrectly error in following code in cpp

本文关键字:代码 错误 终止 cpp 声明      更新时间:2023-10-16

我正试图为观察者模式开发C++程序,但我遇到了这些错误。这是我的CPP代码,我不断地收到错误:"声明终止错误"!提前感谢请帮帮我,我绝望了。

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class Subject{
public :        virtual ~Subject();
virtual float attach()=0;
virtual int notify()=0;
};
class Observer{
public :        virtual ~Observer();
virtual void update(int type, float amount, float bal)=0;
};
class Account : public Subject
{
public:  float attach()
{
char name[12];
int account_no;
float bal;
cout<<"Enter the Name of Account Holder : ";
cin>>name;
cout<<"Enter the Account No. : ";
cin>>account_no;
cout<<"Enter the Balance of his account : ";
cin>>bal;
cout<<"The Name of Account Holder : "<<name;
cout<<"The Account No. : "<<account_no;
cout<<"The Balance of his account : "<<bal;
return bal;
}
int notify()
{
int type;
cout<<"nMenu :nn1) Depositn2)Withdrawln";
cout<<"Enter the type  for transition : n";
cin>>type;
return type;
}
public: void update(int type, float amount, float bal)
{
char name[12];
int account_no;
if(type==1)
bal=bal+amount;
else if(type==2)
bal=bal-amount;
else
cout<<"Oops! Transition Type is invalild....";
cout<<"nThe Details of Account Holder after Transition     :-n";
cout<<"The Name of Account Holder : "<<name;
cout<<"The Account No. : "<<account_no;
cout<<"The Balance of his account : "<<bal;
}
};
class obpt{
public : static void main()
{
Account ac;
//AccountUpdate au;
float balance, amt;
int type;
clrscr();
cout<<"nWelcome To The Program of Observer Pattern of Account Transitionn";
cout<<"nEnter the Details of Account Holder :-n";
balance = ac.attach();
cout<<"nCall notification for Deposit or Withdrawl Transitionn";
type=ac.notify();
cout<<"nEnter the amount for transition : n";
cin>>amt;
cout<<"nAfter The transition the Main balance : n";
ac.update(type, amt, balance);
getch();
}
}

在类声明的末尾缺少一个;。正确:

class Foo
{
/*...*/
};

C++中,main应该是一个自由函数,obpt类是错误的。

int main()
{
/* ... */
}

您收到的错误消息来自编译器。声明声明语句没有正确结束。

在代码的某个地方,您缺少了一个分号;可能在类声明的末尾,或者在定义变量之后。

如果没有看到你的代码,我就无法确定问题所在,但如果你双击它,错误消息应该会把你带到行!

问候,拉凯什。