I have created an Overdrawn class and an Account class. The Account class is generating an
exception of Overdrawn type when the amount to debit becomes greater than the current balance,
Can some body please look into my code & find out the error. The project has three files:
Account.h, Overdrawn.h & main.cpp
//main.cpp
#include "iostream.h"
#include "Account.h"
#include "iostream.h"
#include "Overdrawn.h"
void main ( ) {
Account acctobj (20.0f);
try {
acctobj.debit ( 100.0f);
}
catch (Overdrawn od){
cout <<"OVERDRAWN";
};
}
//Account.h
#include "Overdrawn.h"
class Account {
float balance;
public:
Account (float initbalance ){
balance = initbalance;
}
float getBalance ( ) {
return balance;
}
void credit (float amount) {
balance +=amount;
}
void debit (float amount) {
if (balance - amount < 0)
throw Overdrawn();
else
balance -= amount;
}
};
//Overdrawn.h
class Overdrawn {
public:
Overdrawn ( ) {
cout <<"Cant overdrawn";
}
};
I am getting the following error message:
d:\vc6_d\exceptions1\overdrawn.h(1) : error C2011: 'Overdrawn' : 'class' type redefinition
Zulfi