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 -
//---------------------------------------------------------------------------
-
-
#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 -
//---------------------------------------------------------------------------
-
-
#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 -
-
#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();
-
-
};
-
-
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!
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.
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!
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).
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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:
|
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...
|
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 {
|
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...
| |
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 {
|
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;
|
by: Valeriu Catina |
last post by:
Hi,
consider the Shape class from the FAQ:
class Shape{
public:
Shape();
virtual ~Shape();
virtual void draw() = 0;
|
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
|
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...
|
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,...
| |
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,...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |