0

I have two classes: Game and inputs. Game class has a constructor that takes no variables, while inputs class takes pointer to Game object as an argument (or at least is supposed to).

In main I create two instances of thes objects:

Game main_game; 
inputs main_inputs(&main_game);

And that is the troublesome part of inputs.h:

class inputs{
public:
   Game *wsk;
   inputs(Game *);
};

The compiler gives me two errors in inputs.h:

1) 'Game' does not name a type 2) expected ')' before '*' token

What am I doing wrong, trying to pass adress of Game object to inputs constructor?

1
  • You have to #include the header with the definition of Game or provide a forward-declaration and do that in the .cpp file. Commented Aug 15, 2017 at 20:51

1 Answer 1

2

It seems you forgot to forward declare Game:

class Game;

class inputs{
public:
   Game *wsk;
   inputs(Game *);
};
Sign up to request clarification or add additional context in comments.

1 Comment

What do you not understand about "'Game' does not name a type"?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.