c++ - Small question concerning redefining member functions -


I am trying to re-define two member tasks with the definition of their parent.
I do not know whether I am right or not, but there are some errors in my code and I do not know.

Some headers:

  class account {public: account (double); Zero credit balance (double); Zero debit balan (double); Double getBalance () console; Protected: double balance; }; Class Checking Account: Public Account {Public: Checking Account (Double, Double); Zero duty credit balance (double); Zero fee debitbelens (double); Private: Double charge = 10; };  

Part of the relevant CPP file:

  zero account :: credit balance (double plus) {if (plus> left) = + plus; And cout & lt; & Lt; "Negative can not be negative."; } Zero account :: debit balance (double minus) {if (zero and lieutenant = = balance) balance - = zero; And cout & lt; & Lt; "Debit amount is greater than account balance."; } Zero Checking Rights :: Fee Credit Balance (Double Plus) {If (plus> 0) {Balance = + Plus; Balance - = fee; } And cout & lt; & Lt; "Negative can not be negative."; } Zero checkingAccount :: Fee DebitBelance (double minus) {if (minus and lieutenant = = balance) {balance - = zero; Balance - = fee; } And cout & lt; & Lt; "Debit amount is greater than account balance."; }  

update:

I added it:

  class account {public: account (double); Virtual zero credit balance (double); Virtual zero debit balance (double); Double getBalance () console; Protected: double balance; };  

Now I get an error: Virtual Outward Declaration

I can use the example of properly starting the fee properly.

Edit 2:

I have tried to change the constructor line for this:

  checking account :: checking account (double intelligible, double-fi ): Account (Initial), Fees (FI) {if (InitBal & lt; 0) initBal = 0; Balance = initBal; Serie Lieutenant; & Lt; "The initial balance was invalid."; If (Fiat & Lt; 0) Fei = 0; Fee = FI; }  

is not working, I'm going to work around with changing the syntax on the part of the file (file). I do not know if anyone will respond to it.

If it is intended that the versions that use the fees for the investigation cases, they say , You want to use virtual methods.

A virtual method is decalared (at least in the base class) as a "virtual" method, and its name is identical and signature in some derivative classes. When called a virtual method, it will call the "highest derivative" version for example.

To do this, simply declare "zero credit balloon (double)"; "And" Debit Debit Balance ";" Virtual "(i.e." virtual zero credit equal (double) "and" virtual zero debitability (double); "Then the" fee credit balance "and" fee debit balance "in the checking ACC" CreditBlobense "and" DebitBalance ".

Edit: Simple example.

  class base {public: declare base (int x); // so that the derivative Classes called hello (); it is called virtual zero; conserved: int x;} square root Pages: Public base {public: derived (int x, int y); // overide base :: sayHello (). Here the virtual keyword is optional Virtual Zero say hello (); protected: x (x) {} Concluded :: Useless (int x, x, x, x, x, x, x, x, x, int y): Base (x), y (y) {} zero base: say hello () {std :: cout &  Lite < :: endl;} Vain derivative: say hello () {std :: cout << lt; "Hello from!" & Lt; std :: andl; std :: COAT & lt; ; "X =" & lt; & Lt; X & LT; & Lt; "Y =" & lt; & Lt; Y & lt; & Lt; Std :: endl; } Int main () {base a (5); A.sayHello (); // "Hello from base! ..." derived b (10, -20); B.sayHello (); // "Derived from Hello! ..." Base * c = & amp; Amp; B; // put the pointer in B, also reference- c-> Say hello // "Hello from fear! ..." because it is a derivative example, this is a base variable}  

Then you can get it again from derivative (Class DerivedAgain: public Derived) and then overload the work too.

You can also get many subclasses from the base, which can have its override for each of the virtual methods, like I did for the derived class.

EDIT2: For example, the variable has been added and how to use the initial list to start the base class and member variable.


Comments

Popular posts from this blog

MVP, design question -

excel - Populate list via a bi-Condition -