Note that there are some explanatory texts on larger screens.

plurals
  1. POSmall question concerning redefining member functions
    text
    copied!<p>I'm trying to redefine two member functions from their parent's definition.<br>I don't know if I have it right or not, but something in my code has errors attached and I can't find out what.<br></p> <p>some of the header:</p> <pre><code>class Account { public: Account(double); void creditBalance(double); void debitBalance(double); double getBalance() const; protected: double balance; }; class CheckingAccount : public Account { public: CheckingAccount(double, double); void feeCreditBalance(double); void feeDebitBalance(double); private: double fee = 10; }; </code></pre> <p>relevant cpp file part:</p> <pre><code>void Account::creditBalance(double plus) { if(plus &gt; 0) balance += plus; else cout &lt;&lt; "Cannot credit negative."; } void Account::debitBalance(double minus) { if(minus &lt;= balance) balance -= minus; else cout &lt;&lt; "Debit amount exceeded account balance."; } void CheckingAccount::feeCreditBalance(double plus) { if(plus &gt; 0){ balance += plus; balance -= fee; } else cout &lt;&lt; "Cannot credit negative."; } void CheckingAccount::feeDebitBalance(double minus) { if(minus &lt;= balance){ balance -= minus; balance -= fee; } else cout &lt;&lt; "Debit amount exceeded account balance."; } </code></pre> <p>UPDATE:</p> <p>I added this:</p> <pre><code>class Account { public: Account(double); virtual void creditBalance(double); virtual void debitBalance(double); double getBalance() const; protected: double balance; }; </code></pre> <p>Now I get error: virtual outside class declaration</p> <p>I could use an example of how to properly initialize fee correctly.</p> <p>EDIT 2:</p> <p>I have tried changing the constructor line to this:</p> <pre><code>CheckingAccount::CheckingAccount(double initBal, double phi) : Account(initBal), fee(phi) { if(initBal &lt; 0) initBal = 0; balance = initBal; cerr &lt;&lt; "Initial balance was invalid."; if(phi &lt; 0) phi = 0; fee = phi; } </code></pre> <p>not working, I'm going to work around with changing syntax on the fee(phi) part. I don't know if anyone will respond to this.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload