i have problems with inheritance implementation. I have a base class Account and 3 derived classes from it: CurrentAccount, SavingAccount and ISAAccount.
The Account class is connected with the Employee class and i'm trying to use the derived class functions in the Employee class.
In the Employee i have declared a pointer
Account **theAccounts;
And here is the rest code.
Employee.cpp
Expand|Select|Wrap|Line Numbers
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Employee.h"
- #include "CurrentAccount.h"
- #include "SavingAccount.h"
- #include "ISAAccount.h"
- //---------------------------------------------------------------------------
- void Employee :: create(TEdit *EnterEmployeeName,
- TEdit *EnterEmployeeSurname,
- TEdit *EnterEmployeeSocialNumber,
- TEdit *EnterEmployeeSalary,
- TEdit *EnterEmployeeHouseName,
- TEdit *EnterEmployeeHouseNo,
- TEdit *EnterEmployeeStreet,
- TEdit *EnterEmployeeTown,
- TEdit *EnterEmployeePostCode,
- TEdit *EnterEmployeeCountry,
- TEdit *EnterDOBdate,
- TEdit *EnterDOBmonth,
- TEdit *EnterDOByear,
- TEdit *EnterEmploymentStartDate,
- TEdit *EnterEmploymentStartMonth,
- TEdit *EnterEmploymentStartYear,
- TEdit *EnterBankCode,
- TEdit *EnterAccountNo,
- TEdit *EnterBalance,
- TEdit *EnterBankName,
- TEdit *EnterRate,
- TEdit *EnterOverdraftLimit,
- TEdit *EnterConditions)
- {
- /////// some other stuff ...
- theAccounts[0]->create(EnterBankCode->Text,
- StrToInt(EnterAccountNo->Text),
- StrToFloat(EnterBalance->Text),
- EnterBankName->Text,
- StrToFloat(EnterRate->Text),
- StrToFloat(EnterOverdraftLimit->Text),
- EnterConditions->Text); //////////////problem
- }
- void Employee :: display (TLabel *NameField,
- TLabel *SurnameField,
- TLabel *SocialNumberField,
- TLabel *SalaryField,
- TMemo *AddressMemo,
- TLabel *DOBLabel,
- TLabel *EmploymentStartDateLabel,
- TLabel *BankCodeLabel,
- TLabel *AccountNoLabel,
- TLabel *BalanceLabel,
- TLabel *BankNameLabel,
- TLabel *RateLabel,
- TLabel *OverdraftLimitLabel,
- TLabel *ConditionsLabel)
- {
- theAccounts[0]->display(BankCodeLabel,
- AccountNoLabel,
- BalanceLabel,
- BankNameLabel,
- RateLabel,
- OverdraftLimitLabel,
- ConditionsLabel); /////// problem
- int flag = theAccounts[0]->CheckBalance(); //////derived class function-can't see
- if (flag == 1) ShowMessage("Your balance exceeds overdraft limit!");
- }
- Employee :: Employee()
- {
- FirstName = "";
- Surname = "";
- SocialNumber = -1;
- Salary = -1;
- DOB = new clsDate();
- EmploymentStartDate = new clsDate();
- HomeAddress = new Address();
- theAccounts = new Account*[3];
- theAccounts[0] = new CurrentAccount();
- theAccounts[1] = new ISAAccount();
- theAccounts[2] = new SavingAccount();
- }
- Employee :: Employee(String aFirstName, String aSurname, double aSalary,
- int aSocialNumber)
- {
- FirstName = aFirstName;
- Surname = aSurname;
- Salary = aSalary;
- SocialNumber = aSocialNumber;
- HomeAddress = new Address();
- DOB = new clsDate();
- EmploymentStartDate = new clsDate();
- theAccounts = new Account*[3];
- theAccounts[0] = new CurrentAccount;
- theAccounts[1] = new ISAAccount;
- theAccounts[2] = new SavingAccount;
- }
- Employee :: ~Employee()
- {
- // delete HomeAddress;
- // HomeAddress = NULL;
- delete DOB;
- delete EmploymentStartDate;
- delete theAccounts[0];
- delete theAccounts[1];
- delete theAccounts[2];
- delete theAccounts;
- }
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
Here is Account.h
Expand|Select|Wrap|Line Numbers
- //---------------------------------------------------------------------------
- #ifndef AccountH
- #define AccountH
- #include<vcl.h>
- //---------------------------------------------------------------------------
- class Account{
- protected:
- String BankCode;
- int AccountNo;
- double Balance;
- String BankName;
- double Rate;
- public:
- void create(String aBankCode,
- int aAccountNo,
- double aBalance,
- String aBankName,
- double aRate);
- void display(TLabel *BankCodeLabel,
- TLabel *AccountNoLabel,
- TLabel *BalanceLabel,
- TLabel *BankNameLabel,
- TLabel *RateLabel);
- void deposit(double Amount);
- void withdraw(double Amount);
- Account();
- ~Account();
- };
- //---------------------------------------------------------------------------
- #endif
I won't include Account.cpp with function implementation, but then there is derived class CurrentAccount.
CurrentAccount.h
Expand|Select|Wrap|Line Numbers
- #ifndef CurrentAccountH
- #define CurrentAccountH
- #include "Account.h"
- class CurrentAccount: public Account{
- private:
- double OverdraftLimit;
- String Conditions;
- public:
- void create(String aBankCode,
- int aAccountNo,
- double aBalance,
- String aBankName,
- double aRate,
- double anOverdraftLimit,
- String Conditions);
- void display(TLabel *BankCodeLabel,
- TLabel *AccountNoLabel,
- TLabel *BalanceLabel,
- TLabel *BankNameLabel,
- TLabel *RateLabel,
- TLabel *OverdraftLimitLabel,
- TLabel *ConditionsLabel);
- double CheckInterest(double EnteredBalance, double theRate);
- int CheckBalance();
- CurrentAccount(String aBankCode,
- int aAccountNo,
- double aBalance,
- double aRate,
- double anOverdraftLimit);
- CurrentAccount();
- ~CurrentAccount();
- };
E2227 Extra parameter in call to Account::create(AnsiString,int,double,AnsiString,d ouble) ,
which means it expects the function parameters to be as in class Account function, although i expected the CurrentAccount to override the function, as the parameters are passed as declared in CurrentAccount functions.
And also,
F1004 Internal compiler error at 0xc4c4e7 with base 0xc10000
Both errors are in the line marked with ///////////problem, in the Employee.cpp
Before there was also an error that int CheckBalance(); is not a member of Account class, but i don't see it now.
What is wrong?? Any help will be appreciated!