Manu Coder
Manu Coder

Reputation: 11

Declaration terminated Incorrectly error in following code in cpp

Iam trying to develop C++ program for observer pattern but i am getting these errors. Here's my CPP code , and i getting error continuously : "Declaration termination incorrectly" ! Thanks in Advance Help me please i am desperate.

#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();
}
}

Upvotes: 0

Views: 43838

Answers (2)

user7594349
user7594349

Reputation: 1

The error message you are receiving is coming from the compiler. It is stating that a declaration statement has not been ended correctly.

Somewhere in your code you are missing a semi-colon ; perhaps at the end of a class declaration or after a variable is defined.

Without seeing your code, there is no way for me to pinpoint the problem, but the error message should take you to the line if you double click it!

Regards, Rakesh.

Upvotes: -1

erenon
erenon

Reputation: 19138

You are missing a ; at the end of the class declaration. Correct:

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

In C++, main should be a free function, the obpt class is wrong.

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

Upvotes: 1

Related Questions