簡體   English   中英

struct Cat(string,string,bool,bool)'必須聲明一個主體,因為它沒有被標記為abstract,extern或局部

[英]struct Cat(string, string, bool, bool)' must declare a body because it is not marked abstract, extern, or partial

這是我的代碼,我不知道出什么問題了,為什么編譯器會說

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;

 namespace _11._2
{
class Cat
{
    private string name = "cat";
    private string type = "gizei";
    private bool water = false;
    private bool yalel = false;
    public Cat(string name, string type, bool water, bool yalel);
    public string meow()
    {
        if (yalel)
            return "Meow Meow Meow";
        else
            return "Meow";
    }

    public bool thirsty()
    {
        return water ? true : false;
    }

    public string info()
    {
        return "My name is " + name + " and my type is " + type;
    }
}
}

我嘗試添加抽象或外部,但錯誤仍然存​​在。

這是由於以下行:

public Cat(string name, string type, bool water, bool yalel);

這是一個構造函數聲明,因此您必須為此方法聲明一個主體:

public Cat(string name, string type, bool water, bool yalel)
{
   // Do something like :
   // this.name = name;
   // this.type = type;
   // etc...
}

嘗試這個

 public Cat(string name, string type, bool water, bool yalel)
  {

  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM