我有一个名为更新帐户的虚拟方法,其中基于从find方法找到的指针并返回到main,该帐户将相应地更新。无法更新对象的属性?
有一个叫做Account的父类,其中Savings来源于。
但是,储蓄不会输出更新的利息,也不会使利息生效。
所有账户有余额和存款不会账户之间改变,这就是为什么我打电话帐户的存款方式
void Savings::UpdateAccount(Date *date)
{
int interestMonths;
short lastYear;
short lastMonth;
float currBal;
//THESE GET THE CURRENT DATE - Differs from the account creation
//date and allows for the calculation of interest
lastMonth = GetAccountMonth();
lastYear = GetAccountYear();
currBal = GetAccountBal();
if (((date -> GetYear () - lastYear) * 12 +
(date -> GetMonth () - lastMonth)) > 0)
{
interestMonths = ((date -> GetYear () - lastYear) * 12 +
(date -> GetMonth () - lastMonth));
for (int index = 0; index < interestMonths; index++)
{
currBal = currBal + (currBal * interestRate);
}
//This method takes the calculated current balance, then
//passes it into the parent class method to update the
//private accountBal attribute.
SetBalance(currBal);
}
}
的问题是,这种方法没有更新的对象和我的平衡我相当确定我的利率计算不是问题。
谢谢你的帮助 - 这种方法现在可以工作。
一般来说,你可以这样做,是的。但是你发布的代码似乎不是你问题的根源,不管这些应该是什么。 –
那么如果没有找到帐户会发生什么?提示调用者将得到一个指针,它不可能知道是对还是错,并尝试对其进行解引用。 –
@ lovestogame227你刚刚编辑了这个问题。请注意:这样做会使所有过去的答案和评论显得无关紧要。 – Cinch