无法调用抽象成员 [英] Cannot call an abstract member

查看:442
本文介绍了无法调用抽象成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做我的,在我处理的抽象类,C#功课。

I am doing my homework in C# in which I dealing with abstract class.

public abstract class Account
{   
    public abstract bool Credit(double amount); 
    public abstract bool Debit(double amount);
}

public class SavingAccount : Account
{
    public override bool Credit(double amount)
    {
        bool temp = true;   
        temp = base.Credit(amount + calculateInterest());  
        return temp;  
    }

    public override bool Debit(double amount)
    {
        bool flag = true;    
        double temp = getBalance();    
        temp = temp - amount;

        if (temp < 10000)
        {
            flag = false;
        }

        else
        {
            return (base.Debit(amount));
        }

        return flag;
    }
}

在我所说的base.Debit()或基地.Credit(),那么它给了我无法调用抽象成员错误。
请帮帮我。

When I call the base.Debit() or base.Credit() then it gives me error of cannot call an abstract member. Please help me.

推荐答案

您不能调用抽象方法,这个想法是,一个方法声明为abstract只需要派生类来定义它。使用 base.Debit 在影响试图调用一个抽象方法,它无法做到的。更仔细地阅读你的代码,我觉得这是你想要什么借记()

You cannot call abstract methods, the idea is that a method declared abstract simply requires derived classes to define it. Using base.Debit is in affect trying to call an abstract method, which cannot be done. Reading your code more closely, I think this is what you wanted for Debit()

public abstract class Account
{
  protected double _balance;

  public abstract bool Credit(double amount);
  public abstract bool Debit(double amount);
}

public class SavingAccount : Account
{
  public double MinimumBalance { get; set; }

  public override bool Debit(double amount)
  {
    if (amount < 0)
      return Credit(-amount);

    double temp = _balance;
    temp = temp - amount;

    if (temp < MinimumBalance)
    {
      return false;
    }
    else
    {
      _balance = temp;
      return true;
    }
  }

  public override bool Credit(double amount)
  {
    if (amount < 0)
      return Debit(-amount);

    _balance += amount;
    return true;
  }
}

这篇关于无法调用抽象成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆