Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9155887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:40:32+00:00 2026-06-17T12:40:32+00:00

First, I manage to implement a state machine in a single header file. I

  • 0

First, I manage to implement a state machine in a single header file. I know I need some forward declarations, and I have to define the states from outside to inside. What I really don’t understand is: How would I do this with multiple files?

My aproach:

  • One header per state
  • One header with all possible states, forward declared
  • each header which declares a state includes the header which declares its context

Then it looks like this:

// forward.h
struct Machine;
struct StA;
struct StB;

// machine.h
#include "forward.h"
struct Machine : sc::state_machine< Machine, StA > {};

// a.h
#include "forward.h" // for StB
#include "machine.h"
struct StA : sc::simple_state< StA, Machine, StB > {};

// b.h
#include "forward.h"
#include "a.h"
struct StB : sc::simple_state< StB, StA > {};

Now it’s left open how to include the whole thing in the program. My idea was to have one header which includes from outside to inside all the states’ headers.

// the_machine.h
#include "forward.h"
#include "machine.h"
#include "a.h"
#include "b.h"

// use this header now where you need the state machine

However, I don’t know if the general idea is ok and even if so, I can’t get this to compile (well, not exactly this but a machine I built following this design principle). Having all in one file it pretty easy once you reaized that context needs to be complete, states need to be forward declared and so on, but splitting for complexity and maintenance reasons frays my nerves … Incomplete type 'StXY' used in nested name specifier and so on.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:40:32+00:00Added an answer on June 17, 2026 at 12:40 pm

    The Incomplete type error often appears if you have messed up the order in which headers get included.

    • Did you use proper include guards in your header files?
    • Sometimes forward declarations get messed up when you have circular includes.
    • Sometimes one copies a header to make a similar header (e.g. a.h and b.h) and forgets to change the include guards. This can be very hard to track down.

    Try the follwing: create an empty .cpp that just includes the_machine.h and only precompile it. There are command line flags for the different compilers that write a file containing the preprocessed translation unit (i.e. one file con0taining all the code the compiler gets to see). Check that file to see if everything is in the order you think it is. Most preprocessors generate #line control commands, telling the compiler (and you) what line of what header/source you are looking at.

    Edit:

    If you want to just #include machine.h, you will have to include the state definitions after the machine definition. That might look odd at a first glance, but this is how it works with templates in general, if you want to split dependant parts. Many people use different file suffixes for the later included parts, because those are no real headers on their own, i.e. you can’t include them solely. Example:

    //Something.h
    template <class T>
    struct Something
    {
       void meow(T const& t);
       int wuff(T const& t, int b);
    };
    
    #include "Something.impl" //or .ipp, or other endings...
    
    //Something.impl
    template <class T>
    void Something<T>::meow(T const& t)
    { /* implement... */ }
    
    template <class T>
    int Something<T>::wuff(T const& t, int b)
    { /* implement... */ }
    

    Your machine.h would look similar – define the machine and include implementations of the states after it. I would not name states’ implementation files X.h, because they are no single headers one could just include and use on their own.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first steps into async/threading so apologies in advance. I need some
I am about finishing my first android app, and i have some questions to
I just need some directions regarding a problem I have, where to look, etc..
I'm currently developing an application where I need to manage the state of several
First a little background: I have already managed to connect to a Microsoft SOAP
I have this var manager = context.ManagerInfoes.Select(m => m.Guid == managerGuid).First(); how can i
I need this roadmap of a Hibernate managed object instance. First, I create an
first take a look on this picture from localScope app : i have 2
first of all some details: I configured security as below in web.xml view plaincopy
i have some questions of how to use the Entity Framework in an enterprise

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.