473,804 Members | 3,074 Online
Bytes | Software Development & Data Engineering Community
+ 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,AnsiStr ing,double) ,
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 1670
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,AnsiStr ing,double)

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,AnsiStr ing,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
1490
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 a finite state machine. Unlike the pear::fsm, this one supports hierarchical states, and I intend to make it available, as well. It exists in both PHP 4 and 5 versions, but only the PHP5 version is relevant for this example. The base class...
2
10476
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 and by member functions and friends of classes derived from this class. Since private access cares about the calling class rather than the calling object, I assumed the same was true for protected access, but the following code fails in MSVC6:
9
4997
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 pointer which points to an instance of a derived class, but when I pass that base class pointer into a function, it can't access the derived object's public functions. Although, the base class pointer does call the appropriate virtual function...
5
1469
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() {} }; class B : public A {
3
1909
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 doSomething of Derived I'd like to access private members of Base from the pointer I receive. The compiler (gcc 4.0) tells me, that Base::foo is protected and it can't access although Derived itself has access to the specified element. Probably its...
13
2849
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
2501
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
2185
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
4121
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 allowed to access the protected data members of the base object. This surprises me. Can someone explain why this is? I suspect there is a good reason and I am just having a slow day to not come up with it myself. Bob
0
9704
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9569
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10302
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9130
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5503
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.