but, while doing that the VS compiler shouts that expression must have class type
, although in the line above i made an instance of that class, now im working on this project from Stack, and not heap so I don't wish to use new
, as i would have to delete that instance afterwards... any advice?
this is what i tried doing,
#include"Game.h"
#include <iostream>
int main()
{
Game g();
g.go();
return 0;
}
As mentioned in the comments, you need to change Game g();
to Game g;
. You only use parentheses when you have values to pass in for the constructor. For example, if your constructor was:
Game(std::string player, int damage);
Then your code should be:
Game g("MyGuy", 22);
However, when you just do Game g();
the compiler reads it like you're trying to declare a function -- which you're, of course, not.