C
C#16mo 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
Angius16mo ago
The error is clear DisplayOptions() is an instance method Thus, it requires an instance
Dahyerin
DahyerinOP16mo ago
Can I change that? Or how do I fix it?
Angius
Angius16mo ago
Either: a) Use an instance of WelcomeMenu b) Make the method static
Dahyerin
DahyerinOP16mo ago
I can't make the method static though, because it is overriding the method from the 'Menu' class.
Angius
Angius16mo ago
You have your answer, then
Dahyerin
DahyerinOP16mo 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
Angius16mo ago
var menu = new WelcomeMenu();
menu.DisplayOptions();
var menu = new WelcomeMenu();
menu.DisplayOptions();
Dahyerin
DahyerinOP16mo ago
Thanks! How do I close a thread?
Angius
Angius16mo ago
$close
MODiX
MODiX16mo ago
Use the /close command to mark a forum thread as answered
Dahyerin
DahyerinOP16mo ago
Thanks
Want results from more Discord servers?
Add your server