我有一个主要的游戏,我正在尝试使用 .go() 方法

I have a main of a game, and i'm trying to get to the method .go()

但是,在这样做的同时,VS 编译器会大喊 expression must have class type,尽管在上面的行中我创建了一个 class 的实例,现在我正在从堆栈而不是堆处理这个项目所以我不想使用 new,因为之后我必须删除那个实例……有什么建议吗? 这就是我尝试做的,

 #include"Game.h"
 #include <iostream>

 int main()
    {
     Game g();
     g.go();
     return 0;
    }

如评论中所述,您需要将Game g();更改为Game g;。仅当您有要为构造函数传入的值时才使用括号。例如,如果您的构造函数是:

 Game(std::string player, int damage);

那么你的代码应该是:

Game g("MyGuy", 22);

但是,当您只是执行 Game g(); 时,编译器会像您试图声明一个函数一样读取它——您当然不是。