简体   繁体   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

Here's my code, I have no idea what is wrong and why does the compiler say that 这是我的代码,我不知道出什么问题了,为什么编译器会说

 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;
    }
}
}

I tried adding abstract or external but the error is still there.. 我尝试添加抽象或外部,但错误仍然存​​在。

This is due to the following line : 这是由于以下行:

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

This is a constructor declaration, so you have to declare a body for this method : 这是一个构造函数声明,因此您必须为此方法声明一个主体:

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

try this 尝试这个

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

  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:必须声明一个主体,因为它没有被标记为抽象,外部或局部 - Error: must declare a body because it is not marked abstract, extern, or partial C#“必须声明一个主体,因为它没有被标记为抽象、外部或部分” - C# “must declare a body because it is not marked abstract, extern, or partial” 必须声明一个主体,因为它没有标记为抽象外部或局部 - must declare a body because it is not marked abstract extern or partial C#必须声明一个主体,因为它没有被标记为抽象,外部或部分 - C# must declare a body because it is not marked abstract, extern, or partial 我没有解决“必须声明一个主体,因为它没有被标记为抽象,外部或部分”的问题吗? - i don't solve “must declare a body because it is not marked abstract, extern, or partial” problem? DispatcherTimer.Start()'必须声明一个主体,因为它在MVC4中未标记为抽象,外部或部分 - DispatcherTimer.Start()' must declare a body because it is not marked abstract, extern, or partial in MVC4 “warp(Vector3)”必须声明一个主体,因为它没有标记为抽象、外部或部分 - 'warp(Vector3)' must declare a body because it is not marked abstract, extern, or partial C# 错误:声明一个主体,因为它没有标记为抽象、外部或部分 - C# errors: declare a body because it is not marked abstract, extern, or partial 必须声明一个主体,因为它没有标记为抽象,外部或部分 - Must declare a body becase it is not marked abstract, extern or partial 获取必须声明一个没有标记为抽象,外部或局部的主体 - get must declare a body it is not marked abstract, extern, or partial
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM