Note that there are some explanatory texts on larger screens.

plurals
  1. POStatic member object initialization
    primarykey
    data
    text
    <p>I'm trying to implement a template for states machines in C++, but I'm not sure how to handle static object members. Each state machine would be defined by its state variables and its transitions (which are structs). For instance:</p> <pre><code>// stm.h template &lt;class T&gt; struct transition { ... transition relevant data depending on state variables T ... }; template &lt;class T&gt; class stm { T *stv; // state variables static struct transition&lt;T&gt; *transitions; // I would like to have only one copy of transitions for stm's of type T ... etc ... }; </code></pre> <p>Now, suppose I'm trying to implement the stm foo:</p> <pre><code>// foo_defs.h struct foo_stv { char a; int b; }; // foo_transitions.h // Note that I'm using a different file to keep everything in order #include "stm.h" #include "foo_defs.h" struct transition&lt;struct foo_stv&gt; foo_transitions[] = { { ... trans1 ... }, ..., { ... transN ... } }; // foo_stm.h #include "stm.h" #include "foo_defs.h" #include "foo_transitions.h" class foo_stm { stm&lt;struct foo_stv&gt; stm; struct foo_stv stv; ... other data ... }; </code></pre> <p>Ok. So each instance of foo_stm should have a different set of state variables, but all instances should use the same transitions. The question is, how should I define/declare <code>stm&lt;struct foo_stv&gt;</code> in order to use <code>foo_transitions</code> as its class level <code>transitions</code> member?</p> <p>Also any advice about C++ coding customs is welcome, since I come from the C coding world and just getting started with some C++ mechanics.</p> <p><strong>EDIT</strong>: Just to make clear my question, I guess you should forget about the stm logic and focus on the following: What's the correct way of doing something like...</p> <pre><code>foo_stm::stm.transitions = foo_transitions; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload