简体   繁体   中英

Cannot Assign to class because it is a method group

Here is a code snippet:

    public Menu(ContentManager Content)
    {
        gameLogic = new GameLogic(Content);
        LoadContent(Content);
    }

That is the constructor for my Menu class in a tiny game I'm doing for a school project. I need to reach the GameLogic, so that I can call it to draw and update from Menu, in case my enum gamestate changes from Menu to Game.

However, Visual Studio has a problem with this, giving me the error that "Cannot assing to gameLogic because it is a Method group". It's not wrong, GameLogic is a class, and a class is a group of methods.

My question is simply, how can I reach GameLogic and call on it's methods in the Menu class without having this problem? Any help would be appreciated!

EDIT:

Upon request I'll be adding more code, here's a more detailed code snippet:

class Menu
{
    GameLogic gameLogic();
    public enum GameState { Menu, Game, HighScore };
    public GameState gameState = GameState.Menu;

    public Menu(ContentManager Content)
    {
        gameLogic = new GameLogic(Content);
        LoadContent(Content);
    }

The line which recieves the error is "gameLogic = new GameLogic(Content);" I added the enum part to show why I need to reach gamelogic, so that I can update the gamelogic or draw it when enum is Game (I'm going to do the same with my HighScoreclass as well, that will show a high score list, so it's good if I get a solution ^^)

GameLogic gameLogic();

Variables don't take () . When you add parenthesis language consider them as "Methods". Change it to the following should get rid of the error

GameLogic gameLogic;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM