473,467 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to access derived class functions?

62 New Member
Hi everyone,

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
  1. //---------------------------------------------------------------------------
  2.  
  3. #include <vcl.h>
  4. #pragma hdrstop
  5.  
  6. #include "Employee.h"
  7.  
  8. #include "CurrentAccount.h"
  9. #include "SavingAccount.h"
  10. #include "ISAAccount.h"
  11.  
  12. //---------------------------------------------------------------------------
  13.  
  14. void Employee :: create(TEdit *EnterEmployeeName,
  15.                         TEdit *EnterEmployeeSurname,
  16.                         TEdit *EnterEmployeeSocialNumber,
  17.                         TEdit *EnterEmployeeSalary,
  18.                         TEdit *EnterEmployeeHouseName,
  19.                         TEdit *EnterEmployeeHouseNo,
  20.                         TEdit *EnterEmployeeStreet,
  21.                         TEdit *EnterEmployeeTown,
  22.                         TEdit *EnterEmployeePostCode,
  23.                         TEdit *EnterEmployeeCountry,
  24.                         TEdit *EnterDOBdate,
  25.                         TEdit *EnterDOBmonth,
  26.                         TEdit *EnterDOByear,
  27.                         TEdit *EnterEmploymentStartDate,
  28.                         TEdit *EnterEmploymentStartMonth,
  29.                         TEdit *EnterEmploymentStartYear,
  30.                          TEdit *EnterBankCode,
  31.                          TEdit *EnterAccountNo,
  32.                          TEdit *EnterBalance,
  33.                          TEdit *EnterBankName,
  34.                          TEdit *EnterRate,
  35.                          TEdit *EnterOverdraftLimit,
  36.                          TEdit *EnterConditions)
  37. {
  38.        /////// some other stuff ...
  39.  
  40.         theAccounts[0]->create(EnterBankCode->Text,
  41.                                 StrToInt(EnterAccountNo->Text),
  42.                                 StrToFloat(EnterBalance->Text),
  43.                                 EnterBankName->Text,
  44.                                 StrToFloat(EnterRate->Text),
  45.                                 StrToFloat(EnterOverdraftLimit->Text),
  46.                                 EnterConditions->Text);      //////////////problem
  47.  
  48. }
  49.  
  50. void Employee :: display (TLabel *NameField,
  51.                          TLabel *SurnameField,
  52.                          TLabel *SocialNumberField,
  53.                          TLabel *SalaryField,
  54.                          TMemo *AddressMemo,
  55.                          TLabel *DOBLabel,
  56.                          TLabel *EmploymentStartDateLabel,
  57.                          TLabel *BankCodeLabel,
  58.                          TLabel *AccountNoLabel,
  59.                          TLabel *BalanceLabel,
  60.                          TLabel *BankNameLabel,
  61.                          TLabel *RateLabel,
  62.                          TLabel *OverdraftLimitLabel,
  63.                          TLabel *ConditionsLabel)
  64.  
  65. {
  66.  
  67.              theAccounts[0]->display(BankCodeLabel,
  68.                                    AccountNoLabel,
  69.                                    BalanceLabel,
  70.                                    BankNameLabel,
  71.                                    RateLabel,
  72.                                    OverdraftLimitLabel,
  73.                                    ConditionsLabel);    /////// problem
  74.  
  75.        int flag = theAccounts[0]->CheckBalance();    //////derived class function-can't see
  76.  
  77.         if (flag == 1) ShowMessage("Your balance exceeds overdraft limit!");
  78.  
  79. }
  80.  
  81.  
  82. Employee :: Employee()
  83. {
  84.         FirstName = "";
  85.         Surname = "";
  86.         SocialNumber = -1;
  87.         Salary = -1;
  88.         DOB = new clsDate();
  89.         EmploymentStartDate = new clsDate();
  90.         HomeAddress = new Address();
  91.  
  92.         theAccounts = new Account*[3];
  93.          theAccounts[0] = new CurrentAccount();
  94.         theAccounts[1] = new ISAAccount();
  95.         theAccounts[2] = new SavingAccount();
  96.  
  97. }
  98.  
  99. Employee :: Employee(String aFirstName, String aSurname, double aSalary,
  100.                         int aSocialNumber)
  101. {
  102.         FirstName = aFirstName;
  103.         Surname = aSurname;
  104.         Salary = aSalary;
  105.         SocialNumber = aSocialNumber;
  106.  
  107.         HomeAddress = new Address();
  108.         DOB = new clsDate();
  109.         EmploymentStartDate = new clsDate();
  110.  
  111.         theAccounts = new Account*[3];
  112.         theAccounts[0] = new CurrentAccount;
  113.         theAccounts[1] = new ISAAccount;
  114.         theAccounts[2] = new SavingAccount;
  115.  
  116. }
  117.  
  118. Employee :: ~Employee()
  119. {
  120.  
  121.         //      delete HomeAddress;
  122.           //   HomeAddress = NULL;
  123.  
  124.  
  125.         delete DOB;
  126.         delete EmploymentStartDate;
  127.  
  128.         delete theAccounts[0];
  129.         delete theAccounts[1];
  130.         delete theAccounts[2];
  131.         delete theAccounts;
  132. }
  133.  
  134. //---------------------------------------------------------------------------
  135.  
  136. #pragma package(smart_init)
  137.  
  138.  
  139.  
  140.  

Here is Account.h

Expand|Select|Wrap|Line Numbers
  1. //---------------------------------------------------------------------------
  2.  
  3. #ifndef AccountH
  4. #define AccountH
  5.  
  6. #include<vcl.h>
  7.  
  8. //---------------------------------------------------------------------------
  9.  
  10. class Account{
  11.         protected:
  12.                   String BankCode;
  13.                   int AccountNo;
  14.                   double Balance;
  15.                   String BankName;
  16.                   double Rate;
  17.  
  18.         public:
  19.                 void create(String aBankCode,
  20.                                 int aAccountNo,
  21.                                 double aBalance,
  22.                                 String aBankName,
  23.                                 double aRate);
  24.  
  25.                 void display(TLabel *BankCodeLabel,
  26.                                TLabel *AccountNoLabel,
  27.                                TLabel *BalanceLabel,
  28.                                TLabel *BankNameLabel,
  29.                                TLabel *RateLabel);
  30.  
  31.                 void deposit(double Amount);
  32.                 void withdraw(double Amount);
  33.  
  34.                 Account();
  35.                 ~Account();
  36.  
  37.  
  38. };
  39.  
  40.  
  41. //---------------------------------------------------------------------------
  42. #endif
  43.  
  44.  

I won't include Account.cpp with function implementation, but then there is derived class CurrentAccount.

CurrentAccount.h
Expand|Select|Wrap|Line Numbers
  1.  
  2. #ifndef CurrentAccountH
  3. #define CurrentAccountH
  4.  
  5. #include "Account.h"
  6.  
  7.  
  8. class CurrentAccount: public Account{
  9.  
  10.         private:
  11.                 double OverdraftLimit;
  12.                 String Conditions;
  13.  
  14.         public:
  15.                 void create(String aBankCode,
  16.                             int aAccountNo,
  17.                             double aBalance,
  18.                             String aBankName,
  19.                             double aRate,
  20.                             double anOverdraftLimit,
  21.                             String Conditions);
  22.  
  23.                 void display(TLabel *BankCodeLabel,
  24.                              TLabel *AccountNoLabel,
  25.                              TLabel *BalanceLabel,
  26.                              TLabel *BankNameLabel,
  27.                              TLabel *RateLabel,
  28.                              TLabel *OverdraftLimitLabel,
  29.                              TLabel *ConditionsLabel);
  30.  
  31.                 double CheckInterest(double EnteredBalance, double theRate);
  32.                 int CheckBalance();
  33.  
  34.                 CurrentAccount(String aBankCode,
  35.                                 int aAccountNo,
  36.                                 double aBalance,
  37.                                 double aRate,
  38.                                 double anOverdraftLimit);
  39.                 CurrentAccount();
  40.                 ~CurrentAccount();
  41.  
  42. };
  43.  
  44.  
i am getting errors:
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!
Nov 18 '07 #1
3 1651
Ganon11
3,652 Recognized Expert Specialist
Have a look at what the virtual keyword does. You need it in C++ to properly implement polymorphism and inheritance.
Nov 18 '07 #2
jewel87
62 New Member
Have a look at what the virtual keyword does. You need it in C++ to properly implement polymorphism and inheritance.
Thanks, i've declared Account functions as virtual, but i'm still having problems:

Employee.cpp(64): E2227 Extra parameter in call to Account::create(AnsiString,int,double,AnsiString,d ouble)

Employee.cpp(64): F1004 Internal compiler error at 0xc4c4e7 with base 0xc10000

And it doesn't see the CheckBalance() function, that is it is searching for it in the Account class, which doesn't have it.
I've read these topics in many books and on the net, but can't resolve this.;(((
Please help me, people!
Nov 19 '07 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
Employee.cpp(64): E2227 Extra parameter in call to Account::create(AnsiString,int,double,AnsiString,d ouble)
The compiler thinks Account::create has 5 arguments. Your code has many more. That is, your call does not jibe with the class definition (which you didn't post).
Nov 20 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Terje Slettebø | last post by:
Well, as is customary when you're new to a group, you tend to post quite a bit, :) so here's one more. Some things I've been wondering about with PHP (5). Today, I worked on an implementation of...
2
by: Kevin Saff | last post by:
Apparently I'm missing something. Stroustrup (15.3) says of protected access: If is protected, its name can be used only by member functions and friends of the class in which it is declared...
9
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
5
by: Daniel Aarno | last post by:
Can anyone provide a good explanation to why the following does not work? After all since A is a public base of B objects of type B ISA object of type A. class A { protected: void foo() {} };...
3
by: Samuel Burri | last post by:
Hi there I got a simple problem. As you can see in the posted source, I have two classes, where one is derived from the other. In fact, they also contain virtual functions. In the function...
13
by: dragoncoder | last post by:
Consider the following code #include <iostream> class Base { public: virtual void say() { std::cout << "Base" << std::endl; } }; class Derived: public base {
6
by: Taran | last post by:
Hi All, I tried something with the C++ I know and some things just seem strange. consider: #include <iostream> using namespace std;
7
by: Valeriu Catina | last post by:
Hi, consider the Shape class from the FAQ: class Shape{ public: Shape(); virtual ~Shape(); virtual void draw() = 0;
10
by: blangela | last post by:
If I pass a base class object by reference (likely does not make a difference here that it is passed by reference) as a parameter to a derived class member function, the member function is not...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.