1

I am attempting to create a poptart vending machine program and am getting an error in relation to what i think is a pointer. When the code is on the screen, i am not getting an issue however, when i attempt to build the code i get an error saying 'Syntax error: missing ';' before '*''

Code:

class State: public Transition
{
protected:
StateContext* currentContext;
public:
State(StateContext* Context);
};

Any suggestions would be appreciated. Cheers

1
  • where is the definition for StateContext? Commented Apr 3, 2014 at 19:26

2 Answers 2

6

(Occasionally the C++ compile error messages can be a little cryptic).

You need to forward declare the class StateContext. Before your class declaration, include the line

class StateContext;

Then in the implementation of State, make sure that the class declaration of StateContext is included.

Sign up to request clarification or add additional context in comments.

Comments

1

You need to include definition of StateContext or forward declare the class StateContext and add header in implementation file:

#include "StateContext.h"

class State: public Transition
{
protected:
StateContext* currentContext;
public:
State(StateContext* Context);
};

or:

class StateContext;

class State: public Transition
{
protected:
StateContext* currentContext;
public:
State(StateContext* Context);
};

Forward declaration allows you to use a pointers or references to class being forwarded without including a header for this class as long as you don't call any method (or use its data) on such a pointer or reference.

1 Comment

any idea that when i add the StateContext file as so #include 'StateContext.h', that i get an error saying, 'fatal error C1014: too many include files : depth = 1024'

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.