I'm having trouble with an assignment I'm doing where we have to design a bank system with quite a few classes and derived classes. The problem is that I don't quite understand how the "virtual" keyword works. I made sure to declare any pure virtual functions in the derived class and to inherit publicly. But when I try to create an instance of the derived class, it tells me that I can't instantiate an object of an abstract class... but I did everything by the book, so I don't understand what's wrong.
No, checkingAccount is no abstract class, but it tried to create an instance of an abstract class in it's constructor. Sorry, you can't create it in the initialization list either.
The assignment says "some of these functions will be pure virtual" for the bankAccount class. If I can't create instances of a class with pure virtual functions, how do I implement this? There are other subclasses of checkingAccount as well.
It's compiling fine when I test similar things in the same file... so I have to assume the problem is that I'm using external CPP files and header files.
Header files shouldn't have global using statements and you shouldn't have any using statements in front of any headers. Your #endif directives shouldn't have anything following them.
And you forgot a const in your checkingAccount::monthlyStatement() function. monthlyStatement() and monthlyStatement() const are two different functions.
Not sure if it helps. I see the default constructor of checkingAccount is not calling the default constructor bankAccount. Maybe this is done automatically by C++? I don't know if it does because I usually am 100% explicit about this type of thing. I would have written:
I corrected everything except the global #includes in the headers. Why shouldn't they be? I do it all the time and have never gotten an error because of it.
Even after the corrections suggested, I'm getting the same error.