C
C#11mo ago
Dahyerin

✅ Confused by constant errors regarding class extension.

Hi all, for my uni course, I need to code a game. I have chosen TicTacToe, but it needs to use different design elements (Factory/Template/Strategy) the more that are successfully implemented are better. I have what I think is correct implementation of my Template method classes, but I can't get the rest of the program to talk to the methods within the extended classes. It throws up the error that an object must be passed to them, but I don't want to pass an object to it, I just want the method to run when it is called by another method/class. I have attached two images that show the issue I am running into - this is a problem amongst the whole program, but its the same error. What have I done wrong? I also don't know how to paste code into this, without it looking weird. Thanks for your help - I am super stressed.
11 Replies
Angius
Angius11mo ago
The error is clear DisplayOptions() is an instance method Thus, it requires an instance
Dahyerin
Dahyerin11mo ago
Can I change that? Or how do I fix it?
Angius
Angius11mo ago
Either: a) Use an instance of WelcomeMenu b) Make the method static
Dahyerin
Dahyerin11mo ago
I can't make the method static though, because it is overriding the method from the 'Menu' class.
Angius
Angius11mo ago
You have your answer, then
Dahyerin
Dahyerin11mo ago
Ok, so how do I use an instance of WelcomeMenu? I thought I was doing that when I call to it in the first picture?
Angius
Angius11mo ago
var menu = new WelcomeMenu();
menu.DisplayOptions();
var menu = new WelcomeMenu();
menu.DisplayOptions();
Dahyerin
Dahyerin11mo ago
Thanks! How do I close a thread?
Angius
Angius11mo ago
$close
MODiX
MODiX11mo ago
Use the /close command to mark a forum thread as answered
Dahyerin
Dahyerin11mo ago
Thanks
Want results from more Discord servers?
Add your server
More Posts
❔ How would you embed a Git commit hash in an assembly?I want to stamp a commit hash into a binary so I can display it in the UI. I'm fine with pulling stu❔ Is it possible to run integration tests with typescript as client and .net api as server?My hope is to test a client written in typescript which calls a .net api in the same solution.✅ .csproj – how to generate nodes dynamically by iterating over a string array ?how can i generate xml code in the .csproj file? i dont want to repeat my actions 10000 times... so ❔ AWS multiple file upload Using API in Razor PageI am trying to send the API request from the razor page. The Endpoint is not hitting the API Control✅ Override (abstract) getter-only property with a setterHello! I was wondering if there is anyway to add a setter to an overridden getter-only property? Cu❔ Proper way to do something in C# (migrating an old Visual Basic library)So I'm rewriting an ancient library and used an automatic transpiler to convert it all from VB.NET t❔ Getting information from web apiSo I created my own web api and am creating a console application that can consume the api. I'm curr❔ Runtime Endianness for Reading Structured Binary DataIs there a standard way to deal with reading structured binary data in from a stream where the endia❔ comples object creationHi people, Can someone give me some ideas on how to handle a complex object creation, meaning some ❔ Get list of indices from a ListI have a result set called "result". I want to use Linq to get a list of distinct items by name and