0

The class Player herits from Deckholder where the property Deck has been declared.

public class Deckholder
{
    public Deck Deck { get; set; }

    public Deckholder(Deck deck)
    {
        Deck = deck;
    }
}
public class Player : Deckholder

{
    public string Name { get; set; }
    public int Score { get; set; }

    public Player(string name, Deck deck)
    {
        Deck = deck;
        Name = name;
        Score = 0;
    }

VSCode tells me, that

No argument that fits the formal parameter "deck" from "Deckholder.Deckholder(Deck) was found."

with red squiggles under the Player-constructor. But how do I fix this? I mean I do have a Deck deck as a parameter and I need that.

3
  • 1
    You have to call the base constructor: public Player(string name, Deck deck) : base(deck). Commented Feb 2, 2022 at 12:48
  • 1
    BTW: this is not an attribute but a property Commented Feb 2, 2022 at 12:53
  • @KlausGütter Ah yes, thank you. Commented Feb 2, 2022 at 12:56

1 Answer 1

3

You have to call the constructor of the Deckholderclass from your constructor of your Player class. Use the base keyword for this:

public Player(string name, Deck deck) : base(deck)
{
    Name = name;
    Score = 0;
}

You don't have to assign deck in the Player class anymore, because it is done in the base constructor.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.