0
votes

im trying to use this method to make my characters but i get the error: inconsistent accessibility:return type'consoleapplication1.Enemigo' is less accesible than method 'consoleapplication1.poringbuilder.makeporing()' its the first time i get this error and i really dont know what to do,i have tried alot of different ways but i get the same mistake plz help >.< namespace ConsoleApplication1 { public static class PoringBuilder { public static Enemigo MakePoring() { return new Enemigo(15, 0, 30,15, false, false,"Poring"); } }

this is another class namespace ConsoleApplication1 { class Enemigo:Personaje { public Enemigo(int Damage, int Defensa, int HP,int MP, bool Evade, bool Counter, string Nombre) : base(Damage, Defensa, HP,MP, Evade, Counter, Nombre) { } } }

this is the parent of all my classes namespace ConsoleApplication1 { class Personaje { public int Damage; public int Defensa;

    public int HP;

    public int MP;
    public bool Evade;
    public bool Counter;
    public string Nombre;
    //public Personaje() { }
    public Personaje(int Damage, int Defensa, int HP,int MP, bool Evade, bool Counter, string Nombre)
    {
        this.Damage = Damage;
        this.Defensa = Defensa;
        this.HP = HP;
        this.MP = MP;
        this.Evade = Evade;
        this.Counter = Counter;
        this.Nombre = Nombre;
    }
}

}

and im using it on the main program like this List EnemigosNoob = new List(); EnemigosNoob.Add(PoringBuilder.MakePoring());

i hope im precise enough >.<

3
You can use the 101010 button to format text as code.itowlson
I am confused with your question, but it seems as u r doing constructor overloading. Ur blank and default constructor doesnt have any body which means either u declare it as abstract or give it blank body, so just put {}, and it should work.Zinx

3 Answers

0
votes
public Poring() : this(/*your default values here*/) {}

Also, for your other constructor ... why are you overriding the values passed in?

0
votes

Poring() is your default constructor. You need to declare it with, at least, a do-nothing body:

public Poring()
{
}

If desired, you can perform default initialisation in the body, though this is best handled by chaining to another constructor as per Anon's answer. In either case, though, you must have those two braces { } to form a body.

0
votes

Since you're not really adding anything to the Enemigo class, I would opt for a factory method sort of thing. Subclassing is normally for when you want to add behaviour to something.

public static class PoringBuilder
{
    public static Enemigo MakePoring()
    {
        return new Enemigo(30, 10, 0, false, false, 15, "Poring");
    }
}

And call it:

EnemigosNoob.Add(PoringBuilder.MakePoring());