473,394 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

E2353 Class '.. ' is abstract because of...

62
Hello,
I am trying to make an abstract base class and 3 derived classes. If i include the derived classes function declarations in the base class and make them virtual and =0, once i add more than one function, i get these errors:

E2352 Cannot create instance of abstract class 'CurrentAccount'
E2353 Class 'CurrentAccount' is abstract because of 'Account::create(double,AnsiString,int,double,Ansi String,double) = 0'

Here is the code. Base class:

Expand|Select|Wrap|Line Numbers
  1.  
  2. class Account{
  3.         protected:
  4.                   String BankCode;
  5.                   int AccountNo;
  6.                   double Balance;
  7.                   String BankName;
  8.                   double Rate;
  9.  
  10.         public:
  11.  
  12.                 virtual void create(String aBankCode,
  13.                             int aAccountNo,
  14.                             double aBalance,
  15.                             String aBankName,
  16.                             double aRate,
  17.                             double anOverdraftLimit,
  18.                             String aConditions)=0;   //implemented in CurrentAccount
  19.  
  20.                virtual void create(double aWithdrawLimit,
  21.                                 String aBankCode,
  22.                                 int aAccountNo,
  23.                                 double aBalance,
  24.                                 String aBankName,
  25.                                 double aRate)=0; //implemented in SavingAccount
  26.  
  27.                 virtual void display(TLabel *BankCodeLabel,
  28.                              TLabel *AccountNoLabel,
  29.                              TLabel *BalanceLabel,
  30.                              TLabel *BankNameLabel,
  31.                              TLabel *RateLabel,
  32.                              TLabel *OverdraftLimitLabel,
  33.                              TLabel *ConditionsLabel)=0;
  34.  
  35.                 virtual int CheckBalance()=0;
  36.  
  37.                 void deposit(double Amount);
  38.                 void withdraw(double Amount);
  39.  
  40.                 Account();
  41.                 ~Account();
  42.  
  43.  
  44. };
  45.  
  46.  
Derived classes:

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include "Account.h"
  3.  
  4. class CurrentAccount: public Account{
  5.  
  6.         private:
  7.                 double OverdraftLimit;
  8.                 String Conditions;
  9.  
  10.         public:
  11.                 void create(String aBankCode,
  12.                             int aAccountNo,
  13.                             double aBalance,
  14.                             String aBankName,
  15.                             double aRate,
  16.                             double anOverdraftLimit,
  17.                             String aConditions);
  18.  
  19.                 void display(TLabel *BankCodeLabel,
  20.                              TLabel *AccountNoLabel,
  21.                              TLabel *BalanceLabel,
  22.                              TLabel *BankNameLabel,
  23.                              TLabel *RateLabel,
  24.                              TLabel *OverdraftLimitLabel,
  25.                              TLabel *ConditionsLabel);
  26.  
  27.                 double CheckInterest(double EnteredBalance, double theRate);
  28.                 int CheckBalance();
  29.  
  30.                 CurrentAccount(String aBankCode,
  31.                                 int aAccountNo,
  32.                                 double aBalance,
  33.                                 double aRate,
  34.                                 double anOverdraftLimit);
  35.                 CurrentAccount();
  36.                 ~CurrentAccount();
  37.  
  38. };
  39.  
  40.  
Expand|Select|Wrap|Line Numbers
  1.  
  2. #include "Account.h"
  3.  
  4. class SavingAccount : public Account{
  5.  
  6.                 private:
  7.                        double WithdrawLimit;
  8.  
  9.                 public:
  10.                        void create(double aWithdrawLimit,
  11.                                 String aBankCode,
  12.                                 int aAccountNo,
  13.                                 double aBalance,
  14.                                 String aBankName,
  15.                                 double aRate);
  16.  
  17.                        void display();
  18.                        void withdraw();
  19.                        SavingAccount();
  20.                        ~SavingAccount();
  21.  
  22. };
  23.  
  24.  
Someone please help!!!!
Nov 20 '07 #1
6 2182
jewel87
62
People, is there anyone to help me? Please, this is very urgent! How to make derived class functions overload the base class function?? They all have different parameter sets, but i can't make it work!
Nov 21 '07 #2
chroot
13
Hi

As I see it, you have two functions void create(...) = 0;

You implement one of them in CurrentAccount and one in SavingAccount, but you would have to implement both functions in both classes to stop them from being abstract.

A class is abstract until all functions virtual ... =0; of all base classes are implemented.

Why do you need both functions create to be virtual .. = 0; ?
Nov 21 '07 #3
jewel87
62
Hi

As I see it, you have two functions void create(...) = 0;

You implement one of them in CurrentAccount and one in SavingAccount, but you would have to implement both functions in both classes to stop them from being abstract.

A class is abstract until all functions virtual ... =0; of all base classes are implemented.

Why do you need both functions create to be virtual .. = 0; ?

What the task was saying, i have to use this code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Account ** theAccounts; // declare in the Employee class (other class connected with Account base class)
  3.  
  4. // In the Employee constructor, allocate memory for
  5. //each element of theAccounts array:
  6. theAccounts = new Account * [3];
  7.  
  8. // Create 3 different accounts for the employee
  9. //object:
  10. theAccounts[0] = new CurrentAccount();
  11. theAccounts[1] = new ISAAccount();
  12. theAccounts[2] = new SavingAccount();
  13.  
  14. // De-allocate memory for theAccounts dynamic
  15. //array in the Employee destructor
  16. delete theAccounts[0];
  17. delete theAccounts[1];
  18. delete theAccounts[2];
  19. delete theAccounts;
  20.  
  21.  
And then access each derived class object from Employee class like this, which should use each derived class own function:


Expand|Select|Wrap|Line Numbers
  1.  
  2. theAccounts[0]->create(EnterBankCode->Text,
  3.                                 StrToInt(EnterAccountNo->Text),
  4.                                 StrToFloat(EnterBalance->Text),
  5.                                 EnterBankName->Text,
  6.                                 StrToFloat(EnterRate->Text),
  7.                                 StrToFloat(EnterOverdraftLimit->Text),
  8.                                 EnterConditions->Text); 
  9.  
For each derived class object i have different sets of arguments in the function,
but if i don't declare them in the base class, i can't access them here. What should i do????? I'm confused, and the teacher is not helping... i need to submit this by tomorrow morning...;(((
Nov 21 '07 #4
chroot
13
Well, the important thing about using polymorphism (which the exercise is about, I suppose), is that the base class ( Account ) can only have functions and members that every class that inherits from it has too.

So, if you want to be able to call Accounts[0]->create( ... ), you must have one function create which takes the same arguments for each class. Only then it is possible to call the function for any Account (CurrentAccount or SavingAccount).

I would try to write a function create( ... ), taking all arguments common to both CurrentAccount and SavingAccount. This function can be overloaded by both functions.

You'll have to do the same for display and CheckBalance, i.e. implement them in each class with the same arguments.

I hope things got less confusing.
Nov 21 '07 #5
jewel87
62
Well, the important thing about using polymorphism (which the exercise is about, I suppose), is that the base class ( Account ) can only have functions and members that every class that inherits from it has too.

So, if you want to be able to call Accounts[0]->create( ... ), you must have one function create which takes the same arguments for each class. Only then it is possible to call the function for any Account (CurrentAccount or SavingAccount).

I would try to write a function create( ... ), taking all arguments common to both CurrentAccount and SavingAccount. This function can be overloaded by both functions.

You'll have to do the same for display and CheckBalance, i.e. implement them in each class with the same arguments.

I hope things got less confusing.
Yeah, thanks, you made it more clear, but what should i do with the data specific for each derived class? i need to pass to each new object additional arguments depending on the class...
Nov 21 '07 #6
chroot
13
Well the easiest way would be to just add more arguments to your function:

Expand|Select|Wrap|Line Numbers
  1. create( commonArgument1, commonArgument2, ..., CurrentAccountArgument1, CurrentAccountArgument2, SavingAccountArgument1);
  2.  
Than, in the overloaded functions, you just ignore the arguments that concern other classes (CurrentAccount::create will ignore SavingAccountArgument1), and give any data when calling this function.

However, this is a very ugly way to do it, as a potential user of the class would get really confused about which arguments are going to be ignored.

In fact, it would be important to know from where you call those create() functions, how you know which kind of Account to create, etc.

You could also make specific functions for each inherited class, which set the specific arguments. It depends on how you're going to use the class.
Nov 21 '07 #7

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

Similar topics

16
by: Merlin | last post by:
Hi Been reading the GOF book and started to make the distinction between Class and Interface inheritance. One question though: Do pure abstract classes have representations? (data members?)...
11
by: Shea Martin | last post by:
I have been programming in C++ for over 4 years. I *think* I knew that a struct could have a constructor but I decided to dig into it a little more today, and found that there is very little...
6
by: Dan Sikorsky | last post by:
If we were to define all abstract methods in an abstract class, thereby making that class non-abstract, and then override the heretofore 'abstract' methods in a derived class, wouldn't that remove...
10
by: Joe | last post by:
My question is more an OOD question. I know *how* to implement both abstract classes and interfaces. Here's my question - under what circumstacnes does one use an abstract class and under what...
12
by: scottt | last post by:
hi, I am having a little problem passing in reference of my calling class (in my ..exe)into a DLL. Both programs are C# and what I am trying to do is pass a reference to my one class into a DLL...
0
by: Craig Buchanan | last post by:
i am trying to build an application that uses plugins to extend the business functionality of an application. i've decided to use inheritance of abstract classes as the mechanism to do this. ...
4
by: N.RATNAKAR | last post by:
hai, what is abstract class and abstract method
0
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass...
4
by: Devon Null | last post by:
I have been exploring the concept of abstract classes and I was curious - If I do not define a base class as abstract, will it be instantiated (hope that is the right word) when a derived class is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.