C
C#2y ago
Gipper

❔ How to instantiate derived class when base class requires args?

Hey, I'll post the code below but I don't think it'll be necessary as I'm pretty sure I know what the problem is just not what to do about it...As the title suggests I have a base class that has only one constructor that requires arguments. When I instantiate an object of the derived class I get an error message that seems to be saying it needs the same data in those args of the original base class object: Program.cs(133,16,133,22): error CS7036: There is no argument given that corresponds to the required parameter 'board' of 'Game.Game(Boards, Menu)' Code below as I said, just in case.
6 Replies
Jimmacle
Jimmacle2y ago
in your derived class's constructor, you have to call the base constructor as an example
public MyDerivedClass(string someArg) : base(someArg) { }
public MyDerivedClass(string someArg) : base(someArg) { }
Gipper
GipperOP2y ago
does this only become a requirement when the base constructor starts requiring args? cause it was working fine before
Jimmacle
Jimmacle2y ago
technically your derived class's constructor always calls the base class constructor as well, it's only when the only available base constructors have arguments that you have to do it explicitly
Gipper
GipperOP2y ago
thank you the kitty in your pfp is cute btw
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server