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

时间:2014-02-10 19:34:34

标签: c++ observer-pattern compile-time

我试图为观察者模式开发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 :\n\n1) Deposit\n2)Withdrawl\n";
    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 Transition\n";
    cout<<"\nEnter the Details of Account Holder :-\n";
    balance = ac.attach();
    cout<<"\nCall notification for Deposit or Withdrawl Transition\n";
    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();
}
}

2 个答案:

答案 0 :(得分:1)

您在课程声明结尾处遗漏了;。正确的:

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

C++中,main应该是免费功能,obpt类是错误的。

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

答案 1 :(得分:-1)

您收到的错误消息来自编译器。它声明声明声明尚未正确结束。

在你的代码的某处,你缺少一个分号;也许在类声明结束时或在定义变量之后。

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

问候,Rakesh。

相关问题