Abstract class inheritance issue

I am (still) working on a bank account project for school in which I instantiate and use different class objects - some of which are abstract class types.

The problem I am now having is deriving an abstract class from another abstract class such as this.

Thank you.

+----------------+
| bankAccount | Abstract class
+----------------+ contains fname, lname, bal
|
|
+----------------+
| checkingAccount| Abstract class
+----------------+ contains virtual function write check
|
|
+----------------+
| svcChgChecking | this is the class I need to instantiate
+----------------+


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef BANK_ACCOUNT
#define BANK_ACCOUNT

#include <string>


using namespace std;

class bankAccount 
{
	public:

		 bankAccount(string fname="", string lname="", double bal = 0); //constructor
		 string getAccountHoldersFname() const; // Get account holders first name
		 string getAccountHoldersLname() const; // Get account holders last name
		 int getAccountNumber() const; 		//get account number
		 double getAccountBalance() const;  // get account balance

		//virtual void getMonthlyStatement(int month) = 0; // Print a statement

		virtual void getMonthlyStatement() = 0; // Print a statement
		virtual void deposit(double depositAmount) = 0; // Deposit money into the account

		virtual void withdraw(double withdrawAmount) = 0; // Withdraw money


	protected: // these can be used in derived classes

		string AccountHoldersFname;
		string AccountHoldersLname;
		int accountNumber;
		double balance;
};
#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#ifndef CHECKING_ACCT
#define CHECKING_ACCT

#include "bankAccount.h"

class checkingAccount : public bankAccount
{

	public:

		checkingAccount(string fname, string lname, double bal);

		virtual void writeCheck() = 0; 

		// base class virtual functions that get overiden
		//void getMonthlyStatement();
		//void deposit(double depositAmount);
		//void withdraw(double withdrawAmount);

	protected:

		int checkCounter;
		double checkAmt;
};
#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#ifndef SER_CHG_CHK
#define SER_CHG_CHK

#include "checkingAccount.h"

class serviceChargeChecking : public checkingAccount
{
	public:

		
		serviceChargeChecking(string fname, string lname, double bal, int checkLimit, double costToWrt);
		void writeCheck(double chkAmt);

		void getMonthlyStatement();
		void deposit(double depAmount);
		void withdraw(double withdrawAmount);

		void setCheckLimit(int chkLimit);
		int getCheckLimit() const;
		void setCostToWrite(double costToWrt);

	private:

		int checkLimit;
		double costToWrite;
		

};
#endif 
So what is you problem or question?

Simply instantiate it using the constructor.
1
2
3
int main ()
{ serviceChargeChecking  svc_cng_chking ("fname", "lname", 100, 100, 0.10);
}

Last edited on
In my main program I am unable to instantiate an object of serviceChargeChecking

I am declaring it like so.

serviceChargeChecking objServiceChargeChecking(fname, lname, depAmount, 5, 2.50);

and during build the compiler complains of the object being an abstract class, - however it shouldn't be. I have no virtual functions in this derived class. I don't know what is wrong.

I have been programming this assignment non stop since last Thursday (probably have close to 40 hours on it), so forgive me if I seem vague on my responses. This assignment is due this Thursday and I am feeling pretty stressed out about it. Thanks.
closed account (D80DSL3A)
The pv function in checkingAccount virtual void writeCheck() = 0;
takes 0 arguments. The function in serviceChargeChecking takes 1 argument
void writeCheck(double chkAmt); so there is still no implementation for writeCheck() in class serviceChargeChecking.
Did you mean to declare virtual void writeCheck(double chkAmt) = 0; in class checkingAccount?
I will try that in a couple of minutes. Makes sense as the compiler sees these as different funtions.


THANK YOU SO MUCH !!!!!! fun2code, that is exactly what the problem was.

Cheers!!
Last edited on
Topic archived. No new replies allowed.